home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / misc / edu / globe099src.lha / Ami-Globe / MAIN.C < prev    next >
C/C++ Source or Header  |  1994-11-17  |  109KB  |  3,081 lines

  1. /************************************************************************/
  2. /*                                                                      */
  3. /*      fichier         : main.c                                        */
  4. /*      projet          : amiglobe                                      */
  5. /*      date création   : 1993                                          */
  6. /*      commentaire     : création des menus, lancement de l'application*/
  7. /*      révision        : $VER: main.c 1.216 (16 Oct 1994)
  8. /*      copyright       : Olivier Collard, Thomas Landspurg             */
  9. /*     $HISTORY:                                                */
  10. /*                                                              */
  11. /*     16 Oct 1994 : 001.216 :  ajout des choix de continents dans liste classement
  12. /*     16 Oct 1994 : 001.215 :  ajout de destruct hook à LV_classement
  13. /*     15 Oct 1994 : 001.214 :  ajoute LV_classement_Compare_hook
  14. /*     12 Oct 1994 : 001.213 :  LV_classement_func
  15. /*                     1993 : 0.01 : version initiale           */
  16. /*                                                                      */
  17. /************************************************************************/
  18.  
  19.  
  20. /************************************************************************/
  21. /*      includes                                                        */
  22. /************************************************************************/
  23.  
  24. /* MUI */
  25. #include <libraries/mui.h>
  26.  
  27. #include <exec/types.h>
  28. #include <exec/io.h>
  29. #include <exec/memory.h>
  30. #include <exec/libraries.h>
  31. #include <libraries/dos.h>
  32. #include <intuition/intuition.h>
  33. #include <graphics/gfxmacros.h>
  34. #include <graphics/gfxbase.h>
  35. #include <libraries/gadtools.h>
  36. #include <libraries/asl.h>
  37.  
  38. /* Prototypes */
  39. #include <clib/alib_protos.h>
  40. #include <clib/exec_protos.h>
  41. #include <clib/dos_protos.h>
  42. #include <clib/icon_protos.h>
  43. #include <clib/graphics_protos.h>
  44. #include <clib/intuition_protos.h>
  45. #include <clib/gadtools_protos.h>
  46. #include <clib/muimaster_protos.h>
  47. #include <clib/asl_protos.h>
  48. #include <clib/diskfont_protos.h>
  49. #include <clib/macros.h>
  50. #include <clib/datatypes_protos.h>
  51. #include <clib/locale_protos.h>
  52. /* ANSI C */
  53. #include <stdlib.h>
  54. #include <string.h>
  55. #include <stdio.h>
  56. #include <ctype.h>
  57. #include <math.h>
  58. #include <time.h>
  59.  
  60. #define REG(x) register __ ## x
  61. #define ASM    __asm
  62. #define SAVEDS __saveds
  63.  
  64. #include <pragmas/exec_pragmas.h>
  65. #include <pragmas/dos_pragmas.h>
  66. #include <pragmas/icon_pragmas.h>
  67. #include <pragmas/graphics_pragmas.h>
  68. #include <pragmas/intuition_pragmas.h>
  69. #include <pragmas/muimaster_pragmas.h>
  70. #include <pragmas/asl_pragmas.h>
  71.  
  72.  
  73. #ifdef  LATTICE
  74. #include        <proto/all.h>
  75. #endif
  76.  
  77. #include "amiglobe_types.h"
  78. #include "database_types.h"
  79. #include "main_protos.h"
  80. #include "map_function_protos.h"
  81. #include "read_bin.h"
  82. #include "read_org.h"
  83. #include "editeur_protos.h"
  84. #include "database_protos.h"
  85. #include "3d_types.h"
  86. #include "3d_protos.h"
  87. #include "divers.h"
  88. #include "map_divers.h"
  89. #include "AmiGlobe_Interf.h"
  90. #include "Flag_Protos.h"  
  91. #include "Iff_Fct_Protos.h"
  92. #include "chemin.h"
  93.  
  94. /* get the PowerWindows 2.0 code */
  95. /*#include "windowdef.h"*/
  96.  
  97. /************************************************************************/
  98. /*      variables externes                                              */
  99. /************************************************************************/
  100.  
  101. extern struct Library *UtilityBase=NULL;
  102. extern struct Library *IconBase=NULL;
  103.  
  104. /* External var used */
  105. extern  COUNTRY *tab_country;
  106. extern  ELEM_REM **tab_elem;
  107. /* pour l'edition seulement; a effacer version finale:*/
  108. short int * tab_new_border=NULL;
  109. int longueur_new_border=0;
  110. /*                                      */
  111. extern int num_first_color;
  112. extern E_Type_Data Type_Donnee;
  113. /************************************************************************/
  114. /*      variables créées                                                */
  115. /************************************************************************/
  116.  
  117. /*preferences*/
  118. PREFERENCE Pref;
  119.  
  120. BOOL Flg_Fond;          
  121.  
  122. struct Library *MUIMasterBase=NULL;
  123. struct Library *FastsincosBase=NULL;
  124. struct Library *DiskfontBase=NULL;
  125. struct Library *GadToolsBase=NULL;
  126. struct Library *DataTypeBase=NULL;
  127. struct Library *LocaleBase=NULL;
  128. struct Library *AslBase=NULL;
  129. struct IntuitionBase *IntuitionBase=NULL;
  130. struct GfxBase  *GfxBase=NULL;
  131. #define DRAW
  132.  
  133. #ifndef MAKE_ID
  134. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  135. #endif
  136.  
  137. typedef enum    {CMD_SELECT,CMD_ZOOM,CMD_POINT_ORIG,CMD_POINT_DEST,
  138.                                  CMD_DONN_EXT,CMD_NEW_POINT} /*CMD_NEW_POINT A EFFACER*/
  139.                         E_ACTION_CMD;
  140. E_ACTION_CMD    action=CMD_SELECT;
  141.  
  142. /*** ids ***/
  143.  
  144. enum ids {
  145.     ID_DUMMY,
  146.     ID_ABOUT,
  147.     ID_DEFAULT_PREF,
  148.     ID_LOAD_TRAJ,
  149.     ID_LOAD_TRAJ_OK,
  150.     ID_SELECT_FILE_TRAJ,
  151.     ID_REDRAW,
  152.     ID_INFO,
  153.     ID_FILL,
  154.     ID_MOVE_PT,
  155.     ID_SHOW_PT,
  156.     ID_SHOW_SEG,
  157.     ID_EDIT,
  158.     ID_MODE_EDIT,
  159.     ID_MODE_NOT_EDIT,
  160.     ID_CREATE_PAYS,
  161.     ID_SEL_CTY,
  162.     ID_NEW_CTY,
  163.     ID_CLASSEMENT_CTY,
  164.     ID_INFO_ELEM,
  165.     ID_SEL_CONT,
  166.     ID_SEL_ELEM,
  167.     ID_ELEM_SET_POINT_ORIG,
  168.     ID_ELEM_SET_POINT_DEST,
  169.     ID_NOT_YET,
  170.     ID_AFF_DATA,
  171.     ID_AFF_DATA_EXT,
  172.     ID_DETAIL_ALL,
  173.     ID_DETAIL_1,
  174.     ID_DETAIL_2,
  175.     ID_DETAIL_3,
  176.     ID_DETAIL_4,
  177.     ID_DETAIL_5,
  178.     ID_LOCALISATION,
  179.     ID_POINT_ORIG_PUT,/* ajouter point origine*/
  180.     ID_POINT_ORIG_REM,/* enlever point origine*/
  181.     ID_POINT_DEST_PUT,
  182.     ID_POINT_DEST_REM,
  183.     ID_DONN_EXT,
  184.     ID_ORGANISATION,
  185.     ID_DISTANCE,
  186.     ID_SURFACE,
  187.     ID_ECHELLE,
  188.     ID_PREFS_AFF,
  189.     ID_DONNEES,
  190.     ID_PROJ,
  191.     ID_GROUPE_CHG,
  192.     ID_PR_X,
  193.     ID_PR_Y,
  194.     ID_PR_Z,
  195. /*    ID_SELECT_FILE,*/
  196.     ID_SELECT_FILE_DONNEE,
  197.     ID_REDRAW_EXT,
  198.     ID_SCREEN,
  199.     ID_NO_FOND,
  200.     ID_AFF_DRAP,
  201.     ID_CLOSE_DRAP,
  202.     ID_SELECT,
  203.     ID_DESELECT,
  204.     ID_OK_DATAS,
  205.     ID_ADD_DATA
  206.     };
  207.  
  208. struct  ObjApp  *My_App=NULL;  
  209.  
  210. #define Offset(x)       ( &(((struct ObjApp *)(0))->x) )
  211.  
  212. int     Tab_Win[16]={
  213.         Offset(WI_Cmd),
  214.         Offset(WI_Param),
  215.         Offset(WI_Sel_Cty),
  216.         Offset(WI_Cmd_Panel),
  217.         Offset(WI_Sel_Cont),
  218.         Offset(WI_Chargement),
  219.         Offset(WI_Datas),
  220.         Offset(WI_Param_Datas),
  221.         Offset(WI_Sel_Elem),
  222.         Offset(WI_Trajectoire),
  223.         Offset(WI_Organisation),
  224.         Offset(WI_Info_Element),
  225.         Offset(WI_Classement),
  226.         Offset(WI_Info),
  227.         -1
  228. };
  229.  
  230. struct NewMenu Menu[] =
  231. {
  232. { NM_TITLE, "Project"  , 0 ,0,0,(APTR)0            },
  233.         { NM_ITEM , "About..." ,"?",0,0,(APTR)ID_ABOUT     },
  234.         { NM_ITEM , NM_BARLABEL, 0 ,0,0,(APTR)0            },
  235.         { NM_ITEM , "Load a path" ,0,0,0,(APTR)ID_LOAD_TRAJ     },
  236.         { NM_ITEM , "Default Pref",0,0,0,(APTR)ID_DEFAULT_PREF },
  237.         { NM_ITEM , "Quit"     ,"Q",0,0,(APTR)MUIV_Application_ReturnID_Quit },
  238. { NM_TITLE, "Selection" , 0 ,0,0,(APTR)0            },
  239.         { NM_ITEM , "Country" ,"p",0,0,(APTR)ID_SEL_CTY   },
  240.         { NM_ITEM , "Continent" ,0,0,0,(APTR)ID_SEL_CONT   },
  241.         { NM_ITEM , "Element" ,0,0,0,(APTR)ID_SEL_ELEM   },
  242. { NM_TITLE, "Preferences" , 0 ,0,0,(APTR)0            },
  243.         { NM_ITEM , "Display parameters" ,"c",0,0,(APTR)ID_PREFS_AFF   },
  244.         { NM_ITEM , "Screen" ,"e",0,0,(APTR)ID_SCREEN   },
  245.         { NM_ITEM , "Detail level" ,0,0,0,(APTR)NULL },
  246.                 { NM_SUB , "Auto" ,"A",0,0,(APTR)ID_DETAIL_ALL },
  247.                 { NM_SUB , "1" ,"1",0,0,(APTR)ID_DETAIL_1 },
  248.                 { NM_SUB , "2" ,"2",0,0,(APTR)ID_DETAIL_2 },
  249.                 { NM_SUB , "3" ,"3",0,0,(APTR)ID_DETAIL_3 },
  250.                 { NM_SUB , "4" ,"4",0,0,(APTR)ID_DETAIL_4 },
  251.                 { NM_SUB , "5" ,"5",0,0,(APTR)ID_DETAIL_5 },
  252. { NM_TITLE, "Functions" , 0 ,0,0,(APTR)0            },
  253.         { NM_ITEM , "Localization Window" ,"l",0,0,(APTR)ID_LOCALISATION   },
  254.         { NM_ITEM , "Info about element" ,0,0,0,(APTR)ID_DONN_EXT   },
  255.         { NM_ITEM , "Source point" ,0,0,0,(APTR)NULL },
  256.                 { NM_SUB , "Set" ,"O",0,0,(APTR)ID_POINT_ORIG_PUT },
  257.                 { NM_SUB , "Remove" ,0,0,0,(APTR)ID_POINT_ORIG_REM },
  258.         { NM_ITEM , "Target point" ,0,0,0,(APTR)NULL   },
  259.                 { NM_SUB , "Set" ,"D",0,0,(APTR)ID_POINT_DEST_PUT },
  260.                 { NM_SUB , "Remove" ,0,0,0,(APTR)ID_POINT_DEST_REM },
  261.         { NM_ITEM , "Data comparison" ,"d",0,0,(APTR)ID_DONNEES  },
  262.         { NM_ITEM , "Redisplay comparison" ,"r",0,0,(APTR)ID_AFF_DATA },
  263.         { NM_ITEM , "Display with background" ,"d",0,0,(APTR)ID_AFF_DATA_EXT  },
  264. { NM_TITLE, "Utilities" , 0 ,0,0,(APTR)0            },
  265.         { NM_ITEM , "Select by flag" ,0,0,0,(APTR)ID_AFF_DRAP   },
  266. /*        { NM_ITEM , "Cities list" ,0,0,0,(APTR)ID_NOT_YET   },     */
  267. /*        { NM_ITEM , "Mountains list" ,0,0,0,(APTR)ID_NOT_YET   },*/
  268.         { NM_ITEM , "Organisations list" ,0,0,0,(APTR)ID_ORGANISATION   },
  269. /*        { NM_ITEM , "External data list" ,0,0,0,(APTR)ID_NOT_YET   },  */
  270. { NM_END  , NULL       , 0 ,0,0,(APTR)0            },
  271. };
  272. /*fonts*/
  273. struct  TextAttr Titre_Font_Attr=
  274.     {"helvetica.font",11,FSF_BOLD,FPF_DISKFONT};
  275. struct  TextFont *Titre_Font;
  276. struct  TextAttr Text_Font_Attr
  277.         ={"topaz.font",8,0,FPF_DISKFONT};
  278. struct  TextFont *Text_Font;
  279. char Titre_Ecran[100];
  280.  
  281.  
  282. UWORD   Tab_Pens[]={(UWORD)(~0) };
  283.  
  284. #define HProp           PropObject, PropFrame, MUIA_Prop_Horiz, TRUE, MUIA_FixHeight, 8, MUIA_Prop_Entries, 111, MUIA_Prop_Visible, 10, End
  285. #define VProp           PropObject, PropFrame, MUIA_Prop_Horiz, FALSE, MUIA_FixWidth , 8, MUIA_Prop_Entries, 111, MUIA_Prop_Visible, 10, End
  286. #define List(ftxt)      ListviewObject, MUIA_Weight, 50, MUIA_Listview_Input, FALSE, MUIA_Listview_List, FloattextObject, MUIA_Frame, MUIV_Frame_ReadList, MUIA_Floattext_Text, ftxt, MUIA_Floattext_TabSize, 4, MUIA_Floattext_Justify, TRUE, End, End
  287.  
  288.  
  289. USHORT quit_flag = FALSE;
  290.  
  291. BOOL    Prise_En_Compte=TRUE;
  292.  
  293. struct Window * OpenWindow ();
  294. struct Screen * OpenScreen ();
  295. void   Aff_Image(struct RastPort *rpG,char *P_Name); 
  296. struct Screen   *sC=NULL;
  297. struct Screen   *sC_Image=NULL; 
  298. struct ViewPort *vP;
  299.  
  300. struct Window *wG;              /* we fetch the RastPort pointer from here */
  301. struct Window *win_info=NULL;
  302. struct Window *win_localisation=NULL;
  303. struct Menu   *MyMenu=NULL;
  304.  
  305. struct RastPort *rpG,*cmd_rpG;
  306.  
  307. struct  TmpRas  tmpras;         /* Pour les areadraw */
  308. struct  AreaInfo myareainfo;
  309. WORD    *areabuffer;
  310. char    *buffer_rast=NULL;
  311.  
  312. int     signal_wG;
  313. int     signal_win_info=0;
  314. int     signal_win_image=0;
  315. int     signal_win_localisation=0;
  316. BOOL     continent_sel[6]= {TRUE,TRUE,TRUE,TRUE,TRUE,TRUE}; 
  317.           /* Continents courants sélectionnés*/
  318. float   distance_orig_dest;
  319. int     flg_edit=FALSE;
  320. int     flg_press=FALSE;
  321. APTR    WI_Drapeaux=NULL;
  322. /* tableau des bitmaps alloues pour les drapeaux des pays */
  323. struct BitMap * Tab_Drapeaux[MAX_COUNTRY];
  324. struct Locale * MyLocale=NULL;
  325.  
  326. extern CLIP clip_max;
  327.  
  328. BOOL    Init_Screen(BOOL );
  329. void    Main_Init_Font(void);
  330. void    Do_Action(int);
  331. /*
  332. __oslibversion=42;
  333.  
  334. ULONG __asm _LibInit   ( register __a0 APTR seglist,
  335.                          register __d0 struct MyLibrary *libbase )
  336. {}
  337.  
  338. void __regargs __autoopenfail(char *lib)
  339. {
  340. printf("zut\n");
  341. } */
  342.  
  343. void Aff_Error(char *Texte,char *Bouton)
  344. {
  345.         static struct EasyStruct ES={
  346.                 sizeof(struct EasyStruct),
  347.                 0,
  348.                 "Ami-Globe : Warning",
  349.                 "",
  350.                 ""
  351.         };
  352.         ES.es_TextFormat   = Texte;
  353.         ES.es_GadgetFormat = Bouton;
  354.  
  355.         if(wG!=NULL)EasyRequest(wG, &ES, NULL);
  356. }
  357.  
  358. /* Bascule les elements selectionnes d'une liste vers une autre */
  359.  
  360. void bascule(APTR Obj_From,APTR Obj_To)
  361. {
  362.                         
  363.         LONG id = -1;
  364.         void    *entree;
  365.         int     *tab_pos,i,Max;
  366.  
  367.         tab_pos=malloc(sizeof(int)*get_max_country());
  368.         if(tab_pos==NULL)return;
  369.  
  370.         for (i=0;;i++)
  371.         {
  372.                 DoMethod(Obj_From,MUIM_List_NextSelected,&id);
  373.                 if (id==-1) break;
  374.                 tab_pos[i]=id;
  375.         }
  376.         Max=i;
  377.         for(i=Max-1;i>=0;i--){          
  378.                 DoMethod(Obj_From,MUIM_List_GetEntry,tab_pos[i],&entree);
  379.                 DoMethod(Obj_To,MUIM_List_Insert,&entree,1,MUIV_List_Insert_Sorted);
  380.                 DoMethod(Obj_From,MUIM_List_Remove,tab_pos[i]);
  381.         }
  382.         free(tab_pos);
  383. }
  384.  
  385. /********** Del Ext Image *****************************/
  386. void Del_Ext_Image(void)
  387. {
  388.         if(sC_Image){
  389.                 if(sC_Image->FirstWindow)CloseWindow(sC_Image->FirstWindow);
  390.                 CloseScreen(sC_Image);
  391.         }
  392.         sC_Image=NULL;
  393.         signal_win_image=NULL;
  394. }
  395.  
  396.  
  397. /****************************************************************************/
  398.  
  399. /* This is for the event handler */
  400. void quit(void)
  401. {
  402.         quit_flag = TRUE;
  403. }
  404.  
  405. void SAVEDS ASM activate_window_func(void)
  406. /*active la fenetre wG chaque fois que l'on active une autre fenêtre*/
  407. {
  408.         ActivateWindow(wG);
  409. }
  410.  
  411. struct Hook activate_window_hook=
  412. {
  413.         {NULL,NULL},
  414.         (void *)activate_window_func,
  415.         NULL,NULL
  416. };
  417.  
  418. void SAVEDS ASM new_border_func(void)
  419. {
  420.         /*printf("cmd new border\n");*/
  421.         longueur_new_border=0;
  422.         tab_new_border=(short int*)malloc(1200);
  423. }
  424.  
  425. struct Hook new_border_hook =
  426. {
  427.         {NULL,NULL},
  428.         (void *)new_border_func,
  429.         NULL,NULL
  430. };
  431.  
  432. void SAVEDS ASM new_point_func(void)
  433. {
  434.         /*printf("cmd new point\n");*/
  435.         action=CMD_NEW_POINT;
  436. }
  437.  
  438. struct Hook new_point_hook=
  439. {
  440.         {NULL,NULL},
  441.         (void *)new_point_func,
  442.         NULL,NULL
  443. };
  444.  
  445. void SAVEDS ASM end_border_func(void)
  446. {
  447.         FILE * fichier_border=NULL;
  448.         char * nom_fichier_border;
  449.         char buffer[30];
  450.         get(My_App->STR_Nom_Border,MUIA_String_Contents,
  451.                                 (APTR)&nom_fichier_border);
  452.         /*printf("cmd end border nom fichier:%s nb de points:%d\n",
  453.                         nom_fichier_border,longueur_new_border);*/
  454.         sprintf(buffer,"ram:%s",nom_fichier_border);
  455.         fichier_border=fopen(buffer,"w");
  456.         fwrite(&longueur_new_border,sizeof(short int),1,fichier_border);
  457.         fwrite(tab_new_border,sizeof(short int),longueur_new_border*3,
  458.                 fichier_border);
  459.         fclose(fichier_border);
  460.         free(tab_new_border);
  461.         tab_new_border=NULL;
  462.         action=CMD_SELECT;
  463. }
  464.  
  465. struct Hook end_border_hook=
  466. {
  467.         {NULL,NULL},
  468.         (void *)end_border_func,
  469.         NULL,NULL
  470. };
  471.  
  472.  
  473. void SAVEDS ASM zoom_func(void)
  474. {
  475.         /*printf("cmd zoom!\n");*/
  476.         flg_press=FALSE;
  477.         action=CMD_ZOOM; 
  478. }
  479.  
  480. struct Hook zoom_hook=
  481. {
  482.         {NULL,NULL},
  483.         (void *)zoom_func,
  484.         NULL,NULL
  485. };
  486.  
  487. void SAVEDS ASM zoom_out_func(void)
  488. {
  489. /*      int sx=Pref.clip_cur.maxx-Pref.clip_cur.minx;
  490.         int sy=Pref.clip_cur.maxy-Pref.clip_cur.miny;
  491.         int minx=Pref.clip_cur.minx-sx/2;
  492.         int maxx=Pref.clip_cur.maxx+sx/2;
  493.         int miny=Pref.clip_cur.miny-sy/2;
  494.         int maxy=Pref.clip_cur.maxy+sy/2;
  495.         printf("cmd zoom out !\n");
  496.         conv_xy(&minx,&miny);
  497.         conv_xy(&maxx,&maxy);
  498.         map_set_zoom(   rpG,minx,miny,maxx,maxy);*/
  499.         if (sC)
  500.         {
  501.                 int x1=-wG->Width/2-1;
  502.                 int y1=-wG->Height/2-1;
  503.                 int y2=wG->Height*3/2+1;
  504.                 int x2=(wG->Width*(y2-y1))/wG->Height+x1;
  505.                 map_set_zoom(   rpG,
  506.                                 x1,y1,
  507.                                 x2,y2
  508.                                 );
  509.         }
  510. }
  511.  
  512. struct Hook zoom_out_hook=
  513. {
  514.     {NULL,NULL},
  515.     (void *)zoom_out_func,
  516.     NULL,NULL
  517. };
  518.  
  519. void SAVEDS ASM zoom_reset_func(void)
  520. {
  521.     map_reset_zoom(rpG);
  522.     Pref.Flg_Aff_Coord=TRUE;
  523. }
  524.  
  525. struct Hook zoom_reset_hook=
  526. {
  527.     {NULL,NULL},
  528.     (void *)zoom_reset_func,
  529.     NULL,NULL
  530. };
  531.  
  532. void SAVEDS ASM aff_donnee_externe_func(void)
  533. {
  534.     char * nom;
  535.     get(My_App->TX_nom_element,MUIA_Text_Contents,&nom);
  536.  
  537.     if(sC_Image)Del_Ext_Image();
  538.  
  539.     sC_Image=Iff_Load_And_Open(nom);
  540.     if(sC_Image)
  541.     {
  542.         signal_win_image=(1<<sC_Image->FirstWindow->UserPort->mp_SigBit);
  543.     }
  544. }
  545.  
  546. struct Hook aff_donnee_externe_hook=
  547. {
  548.     {NULL,NULL},
  549.     (void *)aff_donnee_externe_func,
  550.     NULL,NULL
  551. };
  552.  
  553. void SAVEDS ASM continent_select_func(void)
  554. {
  555.     int position=MUIV_List_NextSelected_Start;
  556.     int i;
  557.     for (i=0;i<6;i++)
  558.         continent_sel[i]=FALSE;
  559.     for (;;)
  560.     {
  561.         DoMethod(My_App->LV_Continent,MUIM_List_NextSelected,&position);
  562.         if (position==MUIV_List_NextSelected_End) 
  563.             break;
  564.         continent_sel[position]=TRUE;
  565.     }
  566. }
  567.  
  568. struct Hook continent_select_hook=
  569. {
  570.     {NULL,NULL},
  571.     (void *)continent_select_func,
  572.     NULL,NULL
  573. };
  574.  
  575. void SAVEDS ASM Tout_Selectionner_func(void)
  576. {
  577.     int i,max;
  578.     COUNTRY * pays;
  579.     set (My_App->LV_Select,MUIA_List_Quiet,TRUE);
  580.     set (My_App->LV_Deselect,MUIA_List_Quiet,TRUE);
  581.     get (My_App->LV_Deselect,MUIA_List_Entries,&max);
  582.     for (i=max-1;i>=0;i--)
  583.     {
  584.         DoMethod (My_App->LV_Deselect,MUIM_List_GetEntry,i,&pays);
  585.         if (pays!=NULL)
  586.         {
  587.             DoMethod(My_App->LV_Select,MUIM_List_InsertSingle,pays,
  588.                 MUIV_List_Insert_Sorted);
  589.             DoMethod(My_App->LV_Deselect,MUIM_List_Remove,i);
  590.         }
  591.     }
  592.     set (My_App->LV_Select,MUIA_List_Quiet,FALSE);
  593.     set (My_App->LV_Deselect,MUIA_List_Quiet,FALSE);
  594. }
  595.  
  596. struct Hook Tout_Selectionner_hook=
  597. {
  598.     {NULL,NULL},
  599.     (void *)Tout_Selectionner_func,
  600.     NULL,NULL
  601. };
  602.  
  603. void SAVEDS ASM Tout_Deselectionner_func(void)
  604. {
  605.     int i,max;
  606.     COUNTRY * pays;
  607.     set (My_App->LV_Select,MUIA_List_Quiet,TRUE);
  608.     set (My_App->LV_Deselect,MUIA_List_Quiet,TRUE);
  609.     get (My_App->LV_Select,MUIA_List_Entries,&max);
  610.     for (i=max-1;i>=0;i--)
  611.     {
  612.         DoMethod (My_App->LV_Select,MUIM_List_GetEntry,i,&pays);
  613.         if (pays!=NULL)
  614.         {
  615.             DoMethod(My_App->LV_Deselect,MUIM_List_InsertSingle,pays,
  616.                 MUIV_List_Insert_Sorted);
  617.             DoMethod(My_App->LV_Select,MUIM_List_Remove,i);
  618.         }
  619.     }
  620.     set (My_App->LV_Select,MUIA_List_Quiet,FALSE);
  621.     set (My_App->LV_Deselect,MUIA_List_Quiet,FALSE);
  622. }
  623.  
  624. struct Hook Tout_Deselectionner_hook=
  625. {
  626.     {NULL,NULL},
  627.     (void *)Tout_Deselectionner_func,
  628.     NULL,NULL
  629. };
  630.  
  631. void  SAVEDS ASM Classement_Continent_func(void)
  632. {
  633.     int i,max;
  634.     COUNTRY * pays;
  635.     Tout_Selectionner_func();
  636.     set (My_App->LV_Select,MUIA_List_Quiet,TRUE);
  637.     set (My_App->LV_Deselect,MUIA_List_Quiet,TRUE);
  638.     get (My_App->LV_Select,MUIA_List_Entries,&max);
  639.     for (i=max-1;i>=0;i--)
  640.     {
  641.         DoMethod (My_App->LV_Select,MUIM_List_GetEntry,i,&pays);
  642.         if (pays!=NULL)
  643.             if (continent_sel[pays->continent]==FALSE)
  644.             {
  645.                 DoMethod(My_App->LV_Deselect,MUIM_List_InsertSingle,pays,
  646.                     MUIV_List_Insert_Sorted);
  647.                 DoMethod(My_App->LV_Select,MUIM_List_Remove,i);
  648.             }
  649.     }
  650.     set (My_App->LV_Select,MUIA_List_Quiet,FALSE);
  651.     set (My_App->LV_Deselect,MUIA_List_Quiet,FALSE);
  652. }
  653.  
  654. struct Hook Classement_Continent_hook=
  655. {
  656.     {NULL,NULL},
  657.     (void *)Classement_Continent_func,
  658.     NULL,NULL
  659. };
  660.  
  661. void SAVEDS ASM Petits_Pays_func(void)
  662. {
  663.     /*elimine tous les pays de pop<1000000 de la liste des  */
  664.     /* pays selectionnés                                    */
  665.     int i,max;
  666.     COUNTRY * pays;
  667.     set (My_App->LV_Select,MUIA_List_Quiet,TRUE);
  668.     set (My_App->LV_Deselect,MUIA_List_Quiet,TRUE);
  669.     get (My_App->LV_Select,MUIA_List_Entries,&max);
  670.     for (i=max-1;i>=0;i--)
  671.     {
  672.         DoMethod (My_App->LV_Select,MUIM_List_GetEntry,i,&pays);
  673.         if (pays!=NULL)
  674.             if (pays->population<1000000)
  675.             {
  676.                 DoMethod(My_App->LV_Deselect,MUIM_List_InsertSingle,pays,
  677.                     MUIV_List_Insert_Sorted);
  678.                 DoMethod(My_App->LV_Select,MUIM_List_Remove,i);
  679.             }
  680.     }
  681.     set (My_App->LV_Select,MUIA_List_Quiet,FALSE);
  682.     set (My_App->LV_Deselect,MUIA_List_Quiet,FALSE);
  683. }
  684.  
  685. struct Hook Petits_Pays_hook=
  686. {
  687.     {NULL,NULL},
  688.     (void *)Petits_Pays_func,
  689.     NULL,NULL
  690. };
  691.  
  692. /* prototype de cmd_new_cty*/
  693. void cmd_new_cty(int);
  694.  
  695. void SAVEDS ASM drapeau_select_func(REG(a1) int *numero,REG(a2) void * on_sen_fout)
  696.  
  697. {
  698.     cmd_new_cty(*numero);
  699.     /*
  700.     int old_country;
  701.     old_country=Pref.country_sel;
  702.     if (old_country!=-1)
  703.     {
  704.         fill_country(Pref.country_sel,0,rpG);
  705.     }
  706.     Pref.country_sel=*numero;
  707.     if (Pref.country_sel==old_country)
  708.     {
  709.         set(My_App->TX_Selectionne,MUIA_Text_Contents,0);
  710.         Pref.country_sel=-1;
  711.     }
  712.     else
  713.     {
  714.         if (Pref.country_sel!=-1)
  715.         {
  716.             set(My_App->TX_Selectionne,MUIA_Text_Contents,
  717.                 get_pays_name(Pref.country_sel));
  718.             fill_country(Pref.country_sel,1,rpG);
  719.             if (win_info!=NULL)
  720.                 cmd_info();
  721.         }
  722.     } */
  723. }
  724.  
  725. struct Hook drapeau_select_hook=
  726. {
  727.     {NULL,NULL},
  728.     (void *)drapeau_select_func,
  729.     NULL,NULL
  730. };
  731.  
  732. void cmd_redraw(void)
  733. {
  734.     /*printf("Cmd redraw!\n");*/
  735.     if (Pref.Flg_Fill_Country)
  736.     {
  737.         Map_Give_Type_Trace(TRACE_PLEIN);
  738.     }
  739.     else
  740.     {
  741.         Map_Give_Type_Trace(TRACE_FIL);
  742.     }
  743.     redraw_map(-1,rpG);
  744.     Pref.Flg_Aff_Coord=TRUE;
  745. }
  746.  
  747.  
  748. void  cmd_add_data(void)
  749. {
  750.     char    *P_Name;
  751.  
  752.     get(My_App->STR_fichier_Donnee,MUIA_String_Contents,(APTR)&P_Name);
  753.     if(strlen(P_Name)!=0){
  754.             if(Dtb_Read_Data_File(P_Name)){
  755.                     Aff_Error("Erreur lecture du fichier de donnee...\n","Ok");
  756.             }else{
  757.                     Dtb_Create_Liste_Data(My_App->LV_Datas);
  758.                     Dtb_Create_Liste_Data(My_App->LV_Data1);
  759.                     Dtb_Create_Liste_Data(My_App->LV_Data2);
  760.             }
  761.     }
  762. }
  763.  
  764.  
  765. void cmd_localisation(void)
  766. {
  767.     ULONG aux_Flg_Draw_Lac=Pref.Flg_Draw_Lac;
  768.     ULONG aux_Flg_Draw_Riv=Pref.Flg_Draw_Riv;
  769.     ULONG aux_Flg_Aff_Country_Name=Pref.Flg_Aff_Country_Name;
  770.     ULONG aux_Flg_Aff_Elem_Rem=Pref.Flg_Aff_Elem_Rem;  
  771.     ULONG aux_Flg_Aff_Trajectoires=Pref.Flg_Aff_Trajectoires;  
  772.     CLIP aux_clip_cur=Pref.clip_cur;
  773.     E_TYPE_PROJ     aux_Type_Proj=Pref.Type_Proj;
  774.     static char titre_localisation[13]="Localisation";      
  775.     struct TmpRas * P_tmpras=
  776.             (struct TmpRas *)malloc(sizeof(struct TmpRas));
  777.     void * rasbuffer;
  778.     if (win_localisation==NULL) /* une seule fenetre localisation à la fois */
  779.     {
  780.         win_localisation=OpenWindowTags(
  781.                 NULL,
  782.                 WA_Left,        (sC->Width)*2/3,
  783.                 WA_Top,         0,
  784.                 WA_Width,       (sC->Width)/3,
  785.                 WA_Height,      (sC->Height)/3,
  786.                 WA_CustomScreen,sC,
  787.                 WA_MinWidth,    (ULONG)50,
  788.                 WA_MinHeight,   (ULONG)50,
  789.                 WA_MaxWidth,    (ULONG)320,
  790.                 WA_MaxHeight,   (ULONG)256,                     
  791.                 WA_Flags,       WFLG_SMART_REFRESH|WFLG_CLOSEGADGET|
  792.                         WFLG_GIMMEZEROZERO|WFLG_DRAGBAR|
  793.                         WFLG_SIZEGADGET|WFLG_DEPTHGADGET,
  794.                 WA_IDCMP,       IDCMP_CLOSEWINDOW|IDCMP_NEWSIZE|IDCMP_MOUSEBUTTONS,
  795.                 TAG_DONE);
  796.                 signal_win_localisation=(1<<win_localisation->UserPort->mp_SigBit);     
  797.     }
  798.     /* allocation TmpRas*/
  799.     if (win_localisation)
  800.     {
  801.         rasbuffer=(char *)AllocRaster(320,256);
  802.         if (rasbuffer==NULL)
  803.                 printf("Error: not enough memory\n");
  804.         InitTmpRas(P_tmpras,rasbuffer,RASSIZE(320,256));                
  805.         win_localisation->RPort->AreaInfo=&myareainfo;
  806.         win_localisation->RPort->TmpRas=P_tmpras;
  807.         
  808.         give_size_window(win_localisation->Width-win_localisation->BorderRight,
  809.                                 win_localisation->Height);
  810.         Pref.Flg_Draw_Lac=0;
  811.         Pref.Flg_Draw_Riv=0;
  812.         Pref.Flg_Aff_Country_Name=0;
  813.         Pref.Flg_Aff_Elem_Rem=0;
  814.         Pref.Flg_Aff_Trajectoires=0;
  815.         Pref.clip_cur=clip_max;
  816.         Map_Give_Type_Proj(PROJ_FLAT);
  817.         map_set_prof(5);
  818.         
  819.         redraw_map(-1,win_localisation->RPort);
  820.         Pref.Flg_Draw_Lac=aux_Flg_Draw_Lac;
  821.         Pref.Flg_Draw_Riv=aux_Flg_Draw_Riv;
  822.         Pref.Flg_Aff_Country_Name=aux_Flg_Aff_Country_Name;
  823.         Pref.Flg_Aff_Elem_Rem=aux_Flg_Aff_Elem_Rem;
  824.         Pref.Flg_Aff_Trajectoires=aux_Flg_Aff_Trajectoires;
  825.         Pref.clip_cur=aux_clip_cur;
  826.         Map_Give_Type_Proj(aux_Type_Proj);
  827.         conv_clip();    
  828.         give_size_window(wG->Width,wG->Height);
  829.         map_set_prof(0);
  830.         SetWindowTitles(win_localisation,titre_localisation,(UBYTE *)~0);
  831.  
  832.         /* libération TmpRas */
  833.         FreeRaster(rasbuffer,320,256);
  834.         free(P_tmpras);
  835.     }
  836. }
  837.  
  838. /************ Ouvre un requester de fichier, et met dans l'objet */
  839. /* String Mui passé en parametre le nom du fichier selectionné   */
  840. /* return FALSE si rien n'a ete selectionne                      */
  841.  
  842. int cmd_select_file(APTR Mui_String)
  843. {
  844.         struct  FileRequester   *my_req=0;
  845.         int     code_ret;
  846.         int     res;
  847.         int     len_dir;
  848.         char    Buffer[200];
  849.         char    *P_Name;
  850.         char    Dir[200];
  851.         char    Name[200];
  852.         int     n;
  853.         code_ret=NULL;
  854.  
  855.         if(AslBase!=0){
  856.            get(Mui_String,MUIA_String_Contents,(APTR)&P_Name);
  857.            n=strlen(P_Name);
  858.            while((P_Name[n]!='/')&&(P_Name[n]!=':')&&(n>0))n--;
  859.            if(n!=0){
  860.                 strncpy(Dir,P_Name,n+1);
  861.                 Dir[n+1]=0;
  862.                 strcpy(Name,&P_Name[n+1]);
  863.            }else{
  864.                 strcpy(Name,P_Name);
  865.                 Dir[0]=0;
  866.            }
  867.            my_req=MUI_AllocAslRequestTags(ASL_FileRequest,
  868.                                         ASLFR_Window,wG,
  869.                                         ASL_Hail,"Select a file",
  870.                                         ASLFR_InitialDrawer ,Dir,
  871.                                         ASLFR_InitialFile,Name,
  872.                                         TAG_END);
  873.             /* A t'on pu obtenir le requester? si non, on sort...               */
  874.            if(my_req!=0){
  875.  
  876.                 /* Ouverture du requester de fichier pour l'utilisateur */
  877.                 res=(int)MUI_AslRequest(my_req,0L);
  878.  
  879.                 if(res != 0){
  880.                         /*printf("Selection:%s + %s\n",my_req->rf_Dir,
  881.                                                 my_req->rf_File);
  882.                         */
  883.                         len_dir=strlen(my_req->rf_Dir);
  884.                         if(     (my_req->rf_Dir[len_dir-1]!='/')&&
  885.                                 (my_req->rf_Dir[len_dir-1]!=':')){
  886.                                 sprintf(Buffer,"%s/%s",my_req->rf_Dir,my_req->rf_File);
  887.                         }else{
  888.                                 sprintf(Buffer,"%s%s",my_req->rf_Dir,my_req->rf_File);
  889.                         }
  890.                         set(Mui_String,MUIA_String_Contents,(APTR)Buffer);
  891.         
  892.                         code_ret=TRUE;
  893.  
  894.                 }
  895.                 MUI_FreeAslRequest(my_req);
  896.           }
  897.         }
  898.         return(code_ret);
  899. }
  900.  
  901. void cmd_change_screen(void)
  902. {
  903.     struct  ScreenModeRequester     *my_req=0;
  904.     int     code_ret;
  905.     int     res;
  906.  
  907.     code_ret=NULL;
  908.  
  909.     if(AslBase!=0){
  910.        my_req=MUI_AllocAslRequestTags(ASL_ScreenModeRequest,
  911.                                     ASL_Hail,"Select a screen mode",
  912.                                     ASLFR_Window,wG,
  913.                                     /* On met les parametres deja present */
  914.                                     ASLSM_InitialDisplayID    ,(ULONG)Pref.DisplayId,
  915.                                     ASLSM_InitialDisplayWidth ,(ULONG)Pref.Width,
  916.                                     ASLSM_InitialDisplayHeight,(ULONG)Pref.Height,
  917.                                     ASLSM_InitialDisplayDepth ,(ULONG)Pref.Depth,
  918.                                     ASLSM_InitialOverscanType ,(ULONG)Pref.OScan,
  919.                                     TAG_END);
  920.         /* A t'on pu obtenir le requester? si non, on sort...               */
  921.        if(my_req!=0){
  922.  
  923.             /* Ouverture du requester de fichier pour l'utilisateur */
  924.             res=(int)MUI_AslRequestTags(my_req,
  925.                                     ASLSM_DoDepth,TRUE,
  926.                                     ASLSM_DoOverscanType,TRUE,
  927.                                     TAG_END);
  928.  
  929.             if(res != 0){
  930.                     if(my_req->sm_DisplayDepth>=4){
  931.  
  932.                             Pref.DisplayId=my_req->sm_DisplayID;
  933.                             Pref.Width    =my_req->sm_DisplayWidth;
  934.                             Pref.Height   =my_req->sm_DisplayHeight;
  935.                             Pref.Depth    =my_req->sm_DisplayDepth;
  936.                             Pref.OScan    =my_req->sm_OverscanType;
  937.  
  938.                             Init_Screen(FALSE);                     
  939.                             cmd_redraw();
  940.                             SetWindowTitles(wG,(UBYTE *)~0,Titre_Ecran );
  941.                             code_ret=TRUE;
  942.                     }else{
  943.                             Aff_Error("ERREUR: il faut quatre plans au minimum!\n","OK");
  944.                     }
  945.             }
  946.             MUI_FreeAslRequest(my_req);
  947.       }
  948.     }
  949.     Main_Init_Font();
  950. /*      return(code_ret);*/
  951. }
  952.  
  953. void cmd_redraw_ext(void)
  954. {
  955.     char    *P_Name;
  956.     Object * chaine;
  957.     get(My_App->PA_chargement_fond,MUIA_Popstring_String,&chaine);
  958.     get(chaine,MUIA_String_Contents,(APTR)&P_Name);
  959.     if (strlen(P_Name)!=0)
  960.     {
  961.         Map_Aff_Fond(P_Name,sC);
  962.         cmd_redraw();
  963.         Flg_Fond=TRUE;
  964.     }
  965. }
  966.  
  967.  
  968. void cmd_point_orig(void)
  969. {
  970.         flg_press=FALSE;
  971.         action=CMD_POINT_ORIG;
  972. }
  973.  
  974. void cmd_point_dest(void)
  975. {                      
  976.         flg_press=FALSE;
  977.         action=CMD_POINT_DEST;
  978. }
  979.  
  980.  
  981. void cmd_info(void)
  982. {
  983.     E_TYPE_PROJ  aux_Type_Proj=Pref.Type_Proj;
  984. /*    static struct AreaInfo win_info_Area;
  985.     static void * areabuffer=NULL;
  986.     static BOOL firsttime=TRUE;
  987.     if (firsttime==TRUE)
  988.         {
  989.             areabuffer=AllocMem(MAX_AREA_PT*5,0L);
  990.             InitArea(&win_info_Area,areabuffer,MAX_AREA_PT);
  991.             firsttime=FALSE;
  992.         }*/
  993. /*    struct TmpRas * P_tmpras=
  994.             (struct TmpRas *)malloc(sizeof(struct TmpRas));
  995.     void * rasbuffer;
  996.     int i;
  997. */    if (Pref.country_sel!=-1)
  998.     {  
  999.         /* préchargement des borders    */
  1000.         /*for (i=0;i<tab_country[Pref.country_sel].nb_borders;i++)
  1001.         {
  1002.             VECT *V;
  1003.             int nb_vect;
  1004.             check_border(tab_country[Pref.country_sel].p_borders[i],
  1005.                 &nb_vect,&V);
  1006.         }*/
  1007.         if (win_info==NULL)            /* une seule fenetre info à la fois */
  1008.         {
  1009.             win_info=OpenWindowTags(
  1010.                     NULL,
  1011.                     WA_Left,        5,
  1012.                     WA_Top,         5,
  1013.                     WA_Width,       MIN(sC->Width-10,256*sC->Width/sC->Height),
  1014.                     WA_Height,      MIN(sC->Height-10,256),
  1015.                     WA_CustomScreen,sC,
  1016.                     WA_MinWidth,    MIN(sC->Width-10,128*sC->Width/sC->Height),
  1017.                     WA_MinHeight,   128L,
  1018.                     WA_MaxWidth,    -1,
  1019.                     WA_MaxHeight,   -1,
  1020.                     WA_Flags,       WFLG_SMART_REFRESH|WFLG_CLOSEGADGET|
  1021.                         WFLG_GIMMEZEROZERO|WFLG_DRAGBAR|
  1022.                         WFLG_SIZEGADGET|WFLG_DEPTHGADGET,
  1023.                     WA_IDCMP,       IDCMP_CLOSEWINDOW|IDCMP_NEWSIZE|IDCMP_MOUSEBUTTONS,
  1024.                     TAG_DONE);
  1025.  
  1026.         }
  1027.         if (win_info)
  1028.         {
  1029. /*            rasbuffer=(char *)AllocRaster(sC->Width,sC->Height);
  1030.             if (rasbuffer==NULL)
  1031.                     printf("Erreur allocation buffer info\n");
  1032.             InitTmpRas(P_tmpras,rasbuffer,RASSIZE(sC->Width,sC->Height));
  1033.             win_info->RPort->AreaInfo=&myareainfo;
  1034.             win_info->RPort->TmpRas=P_tmpras;                            */
  1035.             signal_win_info=(1<<win_info->UserPort->mp_SigBit);     /* allocation TmpRas*/
  1036.             win_info->RPort->AreaInfo=&myareainfo;
  1037.             /*win_info->RPort->AreaInfo=&win_info_Area;*/
  1038.             win_info->RPort->TmpRas=rpG->TmpRas;
  1039.             Map_Give_Type_Proj(PROJ_FLAT);
  1040.             aff_info(Pref.country_sel,win_info->RPort,win_info);
  1041.             Map_Give_Type_Proj(aux_Type_Proj);
  1042.             give_size_window(wG->Width,wG->Height);
  1043.             WaitBlit();
  1044.             /* libération TmpRas */
  1045.             /*FreeRaster(rasbuffer,sC->Width,sC->Height);
  1046.             free(P_tmpras);*/
  1047.         }
  1048.         else
  1049.         {
  1050.             Aff_Error("Error opening info window!\n(not enough memory)\n",
  1051.             "OK");
  1052.             printf("Error opening info window!\n(not enough memory)\n");
  1053.         }
  1054.         /*ActivateWindow(wG);*/ /* ne pas mettre d'activate window ici*/
  1055.     }
  1056.     else
  1057.     if (win_info==NULL)
  1058.         Aff_Error("You have not selected any country!","Understood");
  1059. }
  1060.  
  1061. void SAVEDS ASM info_func(void)
  1062. {
  1063.     cmd_info();
  1064. }
  1065.  
  1066. struct Hook info_hook=
  1067. {
  1068.     {NULL,NULL},
  1069.     (void *)info_func,
  1070.     NULL,NULL
  1071. };
  1072.  
  1073. void cmd_donn_ext(void)
  1074. {
  1075.         action=CMD_DONN_EXT;
  1076. }
  1077.  
  1078. void cmd_organisation(void)
  1079. {
  1080.     ULONG drapeau;
  1081.     static BOOL FirstTime=TRUE;
  1082.     get (My_App->WI_Organisation,MUIA_Window_Open,&drapeau);
  1083.     if (!drapeau)
  1084.     {
  1085.         if (FirstTime==TRUE)
  1086.             Create_CY_organisation();
  1087.         FirstTime=FALSE;
  1088.         set (My_App->WI_Organisation,MUIA_Window_Open,TRUE);
  1089.     }
  1090. }
  1091.  
  1092.  
  1093. void cmd_not_yet(void)
  1094. {
  1095.  
  1096.         Aff_Error(
  1097.                 "I'm sorry,but this function is not yet\nimplemented. But soon...",
  1098.                 "Ok,I'll wait for it!");        
  1099. }
  1100.  
  1101. void cmd_about(void)
  1102. {
  1103.         static struct EasyStruct ES={
  1104.                 sizeof(struct EasyStruct),
  1105.                 0,
  1106.                 "About Magellan ",
  1107. "Magellan, by Thomas Landspurg & Olivier Collard\n\n"
  1108. "This program allow you to nagivate throught the\n"
  1109. "world, zooming evrywhere, etc...\n\n"
  1110. " This program will be shareware, but\n"
  1111. "without any limitation.\n",
  1112. "Thanks Man",
  1113.         };
  1114.  
  1115.         EasyRequest(wG, &ES, NULL);
  1116. }
  1117.  
  1118.  
  1119. /****************************************************************************/
  1120.  
  1121.  
  1122. /*******************************************************************************/
  1123.  
  1124. void    cmd_sel_cty(void)
  1125. {
  1126.         set(My_App->WI_Sel_Cty,MUIA_Window_Open,(APTR)TRUE);
  1127. }
  1128.  
  1129. //void SAVEDS ASM list_rawkey_func(REG(a2) Object * list,REG(a1) char *caractere)
  1130. /* le char * est bien un pointeur sur char et pas une chaîne */
  1131. /*{
  1132.  
  1133. }
  1134.  
  1135. struct Hook list_rawkey_hook =
  1136. {
  1137.         {NULL,NULL},
  1138.         (void *)list_rawkey_func,
  1139.         NULL,NULL
  1140. };*/
  1141.  
  1142.  
  1143. /***********************************************************************/
  1144. /*  display hooks pour les listes MUI                                  */
  1145. /***********************************************************************/
  1146.  
  1147. void
  1148. SAVEDS ASM LV_Elements_Display_func(REG(a2) char **array,REG(a1) ELEM_REM * element)
  1149. {
  1150.     array[0]=element->Nom;
  1151. }
  1152.  
  1153. struct Hook LV_Elements_Display_hook=
  1154. {
  1155.     {NULL,NULL},
  1156.     (void *)LV_Elements_Display_func,
  1157.     NULL,NULL
  1158. };
  1159.  
  1160. SAVEDS ASM LONG LV_Elements_Compare_func(REG(a1) ELEM_REM *elem1,REG(a2) ELEM_REM * elem2)
  1161.  
  1162. {
  1163.     return stricmp(elem1->Nom,elem2->Nom);
  1164. }
  1165.  
  1166. struct Hook LV_Elements_Compare_hook=
  1167. {
  1168.     {NULL,NULL},
  1169.     LV_Elements_Compare_func,
  1170.     NULL,NULL
  1171. };
  1172.  
  1173. void
  1174. SAVEDS ASM LV_classement_Display_func(REG(a2) char **array,REG(a1) DATA_TRI * donnee)
  1175. {
  1176.     static char buffer1[8],buffer2[32];
  1177.     sprintf(buffer1,"\0333%d",donnee->Rang);/* numero de ligne*/
  1178.     switch(Type_Donnee)
  1179.     {
  1180.         case DATA_INTEGER:
  1181.             Map_Put_Million(buffer2,"\0333\033r%s",donnee->valeur.data_int);
  1182.             /*sprintf(buffer2,"\0333%d",donnee->valeur.data_int);*/
  1183.             break;
  1184.         case DATA_FLOAT:
  1185.             sprintf(buffer2,"\0333\033r%.2f",donnee->valeur.data_float);
  1186.             break;
  1187.         case DATA_PERCENT:
  1188.             sprintf(buffer2,"\0333\033r%.2f%%",donnee->valeur.data_float);
  1189.             break;
  1190.         default:
  1191.             break;
  1192.     }    
  1193.     array[0]=buffer1;
  1194.     array[1]=tab_country[donnee->Num_Pays].name;
  1195.     array[2]=buffer2;
  1196. }
  1197.  
  1198. struct Hook LV_classement_Display_hook=
  1199. {
  1200.     {NULL,NULL},
  1201.     (void *)LV_classement_Display_func,
  1202.     NULL,NULL
  1203. };         
  1204.  
  1205. void
  1206. SAVEDS ASM LV_classement_Destruct_func(REG(a2) APTR pool,REG(a1) DATA_TRI * donnee)
  1207. {
  1208.     free(donnee);
  1209. }
  1210.  
  1211. struct Hook LV_classement_Destruct_hook=
  1212. {
  1213.     {NULL,NULL},
  1214.     (void *)LV_classement_Destruct_func,
  1215.     NULL,NULL
  1216. };
  1217.  
  1218. void cmd_sel_elem(void)
  1219. {               
  1220.     static BOOL liste_cree=FALSE;
  1221.     if (liste_cree==FALSE)
  1222.     {
  1223.         create_tab_elem();
  1224.  
  1225.         DoMethod(My_App->LV_Elements,MUIM_List_Insert,
  1226.             tab_elem,-1,MUIV_List_Insert_Bottom);
  1227.  
  1228.         liste_cree=TRUE;
  1229.         set(My_App->LV_Elements,MUIA_List_CompareHook,
  1230.             &LV_Elements_Compare_hook);
  1231.         set(My_App->LV_Elements,MUIA_List_DisplayHook,
  1232.             &LV_Elements_Display_hook);
  1233.         DoMethod(My_App->LV_Elements,MUIM_List_Sort);                           
  1234.     }
  1235.     set(My_App->WI_Sel_Elem,MUIA_Window_Open,(APTR)TRUE);
  1236. }       
  1237.  
  1238. /*******************************************************************************/
  1239. void
  1240. cmd_new_cty(int num_cty)
  1241. {
  1242.     //int     num_cty;
  1243.     int old_country;
  1244.     //num_cty=Dtb_Find_Country_Pos(p_name);
  1245.     if(num_cty!=-1)
  1246.     {
  1247.         old_country=Pref.country_sel;
  1248.         if (old_country!=-1)
  1249.             fill_country(old_country,0,rpG);
  1250.         Pref.country_sel=num_cty;
  1251.         if (Pref.country_sel==old_country) /* déselection d'un pays*/
  1252.         {
  1253.             set(My_App->TX_Selectionne,MUIA_Text_Contents,
  1254.                     0);
  1255.             Pref.country_sel=-1;
  1256.         }
  1257.         else
  1258.         {
  1259.             /*BOOL ouverture;*/
  1260.             int i;
  1261.             set(My_App->TX_Selectionne,MUIA_Text_Contents,
  1262.                     tab_country[num_cty].name);
  1263.             fill_country(Pref.country_sel,1,rpG);
  1264.  
  1265.             /* SI la fenetre d'info sur pays est ouverte */
  1266.             if(win_info != NULL)
  1267.                 cmd_info();
  1268.             /*get (My_App->WI_Classement,MUIA_Window_Open,&ouverture);*/
  1269.             /* si la fenêtre de comparaison de données est ouverte */
  1270.             DoMethod(My_App->LV_classement,MUIM_List_Select,MUIV_List_Select_All,
  1271.                 MUIV_List_Select_Off,NULL);
  1272.             for (i=0;;i++)
  1273.             {
  1274.                 DATA_TRI * donnee;
  1275.                 DoMethod(My_App->LV_classement,MUIM_List_GetEntry,i,&donnee);
  1276.                 if (donnee==NULL)
  1277.                     break;
  1278.                 if (donnee->Num_Pays==num_cty)
  1279.                 {
  1280.                     DoMethod(My_App->LV_classement,MUIM_List_Jump,i);
  1281.                     DoMethod(My_App->LV_classement,MUIM_List_Select,i,
  1282.                         MUIV_List_Select_On,NULL);
  1283.                 }
  1284.             }
  1285.         }
  1286.     }
  1287. }
  1288.  
  1289. /*********************************************************/
  1290. void cmd_redraw_datas(void)
  1291. {
  1292.     int     type_graph;
  1293.     int     dtb_sel=-1;
  1294.  
  1295.     get(My_App->LV_Datas,MUIA_List_Active,&dtb_sel);
  1296.     get(My_App->RA_Type_Graph,MUIA_Radio_Active,&type_graph);
  1297.     /*printf("Active:%d,type:%d\n",dtb_sel,type_graph);*/
  1298.     if(dtb_sel!=-1)
  1299.     {
  1300.         /*set(My_App->WI_Datas     ,MUIA_Window_Open,(APTR)FALSE);*/
  1301.         Dtb_Aff_Result(rpG,dtb_sel,My_App->LV_Select,type_graph);
  1302.     }
  1303.     else
  1304.     {
  1305.         Aff_Error("Select first a data type...\n","Ok");
  1306.     }
  1307. }               
  1308.  
  1309.  
  1310. /*********************************************************/
  1311. void cmd_new_3d(void)
  1312. {
  1313.     long    int     posx,posy,sizex,sizey;
  1314.     int     x,y,i;
  1315.     struct  Window  *win;
  1316.     struct  RastPort *rp;
  1317.     PREFS_3D        Prefs,Old_Prefs;
  1318.     static  int     tab_car[][2]={
  1319.                             {-100,-50},
  1320.                             { 100,-50},
  1321.                             { 100, 50},
  1322.                             {-100, 50},
  1323.                             {-100,-50}
  1324.                             };
  1325.  
  1326.     get(My_App->SL_x,MUIA_Slider_Level,&Pref.SL_x);
  1327.     get(My_App->SL_y,MUIA_Slider_Level,&Pref.SL_y);
  1328.     get(My_App->SL_z,MUIA_Slider_Level,&Pref.SL_z);
  1329.     get(My_App->IM_Rectangle,MUIA_Width   ,&sizex);
  1330.     get(My_App->IM_Rectangle,MUIA_Height  ,&sizey);
  1331.     get(My_App->IM_Rectangle,MUIA_LeftEdge,&posx);
  1332.     get(My_App->IM_Rectangle,MUIA_TopEdge ,&posy);
  1333.  
  1334.     Prefs.ax=2*PI*( ((float)Pref.SL_x)/360 );
  1335.     Prefs.ay=2*PI*( ((float)Pref.SL_y)/360 );
  1336.     Prefs.az=2*PI*( ((float)Pref.SL_z)/360 );
  1337.  
  1338.     sizex-=4;
  1339.     sizey-=4;
  1340.     posx+=2;
  1341.     posy+=2;
  1342.     Prefs.sizex=sizex;
  1343.     Prefs.sizey=sizey;
  1344.     Prefs.centre_x=posx+sizex/2;
  1345.     Prefs.centre_y=posy+sizey/2;
  1346.     Prefs.de=300;
  1347.     Old_Prefs=T3D_Set_Prefs(Prefs);
  1348.     Old_Prefs.ax=Prefs.ax;
  1349.     Old_Prefs.ay=Prefs.ay;
  1350.     Old_Prefs.az=Prefs.az;
  1351.     Old_Prefs.centre_x=wG->Width/2 ;
  1352.     Old_Prefs.centre_y=wG->Height/2;
  1353.     Old_Prefs.sizex   =wG->Width   ;
  1354.     Old_Prefs.sizey   =wG->Height  ;
  1355.  
  1356.     get(My_App->WI_Param,MUIA_Window_Window,&win);
  1357.  
  1358.     if(win!=NULL)
  1359.     {
  1360.         rp=win->RPort;
  1361.         SetAPen(rp,0);
  1362.         RectFill( rp,   posx,posy,
  1363.                         posx+sizex,posy+sizey
  1364.                 );
  1365.         SetAPen(rp,1);
  1366.  
  1367.         for(i=0;i<5;i++)
  1368.         {
  1369.             x=tab_car[i][0]+Prefs.centre_x;
  1370.             y=tab_car[i][1]+Prefs.centre_y;
  1371.             T3D_Convert(x,y,&x,&y);
  1372.             if(i==0)
  1373.             {
  1374.                 Move(rp,x,y);
  1375.             }
  1376.             else
  1377.             {
  1378.                 Draw(rp,x,y);
  1379.             }
  1380.         }
  1381.     }
  1382.     T3D_Set_Prefs(Old_Prefs);
  1383. }
  1384.  
  1385. /*********************************************************/
  1386. /* Initialisation des fontes pour une fenetre donnees    */
  1387.  
  1388. void Main_Init_Font(void)
  1389. {
  1390.     struct Window * win;
  1391.     get(My_App->WI_Cmd,MUIA_Window_Window,&win);
  1392.     if (win!=NULL)
  1393.     /* on essaie de recuperer la police de MUI*/
  1394.             AskFont(win->RPort,&Text_Font_Attr);
  1395.     /*printf("nom de la fonte:%s\n",Text_Font_Attr.ta_Name);*/
  1396.     if (DiskfontBase)
  1397.     {
  1398.         Titre_Font = OpenDiskFont(&Titre_Font_Attr);
  1399.         Text_Font  = OpenDiskFont(&Text_Font_Attr );
  1400.         Map_Give_Default_Font( Titre_Font, Text_Font );
  1401.         SetFont(rpG,Text_Font);
  1402.     }
  1403. }
  1404.  
  1405. /********** Del Screen Image *****************************/
  1406. void Del_Image(void)
  1407. {
  1408.         Map_Del_Fond();
  1409.         if(sC){
  1410.                 Map_Set_Default_Colors(vP);
  1411.                 cmd_redraw();
  1412.                 Flg_Fond=FALSE;
  1413.         }
  1414. }
  1415.  
  1416. /**********************************************************/
  1417.  
  1418. static VOID fail(APTR app,char *str)
  1419. {
  1420.     /*printf("Appel a fail\n");*/
  1421.         if (app)
  1422.                 MUI_DisposeObject(app);
  1423.  
  1424.         if (MUIMasterBase)
  1425.                 CloseLibrary(MUIMasterBase);
  1426.  
  1427.         if (str)
  1428.         {
  1429.                 puts(str);
  1430.                 exit(20);
  1431.         }
  1432.         exit(0);
  1433. }
  1434.  
  1435. static VOID init(VOID)
  1436. {
  1437. #ifndef _DCC
  1438.         if (!(MUIMasterBase = OpenLibrary (MUIMASTER_NAME,7)))
  1439.                 fail(NULL,"Failed to open "MUIMASTER_NAME".");
  1440. #endif
  1441. }
  1442.  
  1443.  
  1444. /***********************************************************************/
  1445.  
  1446. /* Initialisation des differentes notifications pour MUI, */
  1447. /* ainsi que de l'etat de depart des fenetres MUI         */
  1448.  
  1449. void Init_Notification(void)
  1450. {
  1451.     static BOOL Flg_MUI_Initiated=FALSE;
  1452.     int     i;
  1453.     /*char buffer[16];*/
  1454.     /*int NumCol =57;*/
  1455.             
  1456.     for(i=0;Tab_Win[i]!=-1;i++)
  1457.     {
  1458.             set ( *(APTR *)((char *)My_App+Tab_Win[i]),
  1459.                             MUIA_Window_Screen,(APTR)sC);
  1460.             DoMethod( * (APTR *)((char *)My_App+Tab_Win[i]),
  1461.                      MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  1462.                      *(APTR *)((char *)My_App+Tab_Win[i]),3,
  1463.                      MUIM_Set,MUIA_Window_Open,FALSE);
  1464.     }
  1465.     /* On indique qu'une fermeture de la fenetre Cmd principale= fermeture  */
  1466.     /* de l'appli                                                           */
  1467.     DoMethod(My_App->WI_Cmd,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  1468.              My_App->App,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  1469.  
  1470.     /* Fermeture de cmd panel                               */
  1471.  
  1472.     DoMethod(My_App->WI_Cmd_Panel,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  1473.             My_App->App,2,MUIM_Application_ReturnID,ID_MODE_NOT_EDIT);
  1474.     /* notification des boutons*/
  1475.     if (Flg_MUI_Initiated==FALSE)
  1476.     {
  1477. /*        DoMethod(My_App->BT_Cmd_Panel,MUIM_Notify,MUIA_Pressed,FALSE,
  1478.                 My_App->WI_Cmd_Panel,3,MUIM_Set,MUIA_Window_Open,TRUE);*/
  1479. /*      DoMethod(My_App->BT_Cmd_Panel,MUIM_Notify,MUIA_Pressed,FALSE,
  1480.                 My_App->App,2,MUIM_Application_ReturnID,ID_MODE_EDIT);*/
  1481. /*        DoMethod(My_App->BT_Fill,MUIM_Notify,MUIA_Pressed,FALSE,
  1482.                 My_App->App,2,MUIM_Application_ReturnID,ID_MODE_EDIT);*/
  1483.         DoMethod(My_App->BT_Info,MUIM_Notify,MUIA_Pressed,FALSE,
  1484.                 My_App->App,2,MUIM_CallHook,&info_hook);
  1485.  
  1486. /*        DoMethod(My_App->BT_Info,MUIM_Notify,MUIA_Pressed,FALSE,
  1487.                 My_App->App,2,MUIM_Application_ReturnID,ID_INFO);*/
  1488. /*        DoMethod(My_App->BT_Fill,MUIM_Notify,MUIA_Pressed,FALSE,
  1489.                 My_App->App,2,MUIM_Application_ReturnID,ID_FILL);*/
  1490.         DoMethod(My_App->BT_Move,MUIM_Notify,MUIA_Pressed,FALSE,
  1491.                 My_App->App,2,MUIM_Application_ReturnID,ID_MOVE_PT);
  1492.         DoMethod(My_App->BT_New_Border,MUIM_Notify,MUIA_Pressed,FALSE,
  1493.                 My_App->App,2,MUIM_CallHook,&new_border_hook);
  1494.         DoMethod(My_App->BT_End_Border,MUIM_Notify,MUIA_Pressed,FALSE,
  1495.                 My_App->App,2,MUIM_CallHook,&end_border_hook);
  1496.         DoMethod(My_App->BT_New_Point,MUIM_Notify,MUIA_Pressed,FALSE,
  1497.                 My_App->App,2,MUIM_CallHook,&new_point_hook);
  1498.         DoMethod(My_App->CY_Proj,MUIM_Notify,MUIA_Cycle_Active,MUIV_EveryTime,
  1499.                 My_App->App,2,MUIM_Application_ReturnID,ID_PROJ);
  1500.  
  1501.         DoMethod(My_App->BT_Zoom,MUIM_Notify,MUIA_Pressed,FALSE,
  1502.                 My_App->App,2,MUIM_CallHook,&zoom_hook);
  1503.  
  1504.         DoMethod(My_App->BT_Zoom_Out,MUIM_Notify,MUIA_Pressed,FALSE,
  1505.                 My_App->App,2,MUIM_CallHook,&zoom_out_hook);
  1506.         DoMethod(My_App->BT_Zoom_Reset,MUIM_Notify,MUIA_Pressed,FALSE,
  1507.                 My_App->App,2,MUIM_CallHook,&zoom_reset_hook);
  1508.         DoMethod(My_App->BT_Show_Pt,MUIM_Notify,MUIA_Pressed,FALSE,
  1509.                 My_App->App,2,MUIM_Application_ReturnID,ID_SHOW_PT);
  1510.  
  1511. //      sprintf(buffer,"\33\57",Num_Col);
  1512.         set(My_App->TX_Selectionne,MUIA_Text_PreParse,"\0333");
  1513.  
  1514.         DoMethod(My_App->BT_Element_Origine,MUIM_Notify,MUIA_Pressed,FALSE,
  1515.                 My_App->App,2,MUIM_Application_ReturnID,ID_ELEM_SET_POINT_ORIG);
  1516.         DoMethod(My_App->BT_Element_Destination,MUIM_Notify,MUIA_Pressed,FALSE,
  1517.                 My_App->App,2,MUIM_Application_ReturnID,ID_ELEM_SET_POINT_DEST);
  1518.  
  1519.         DoMethod(My_App->BT_Show_Seg,MUIM_Notify,MUIA_Pressed,FALSE,
  1520.                 My_App->App,2,MUIM_Application_ReturnID,ID_SHOW_SEG);
  1521.         DoMethod(My_App->BT_Edit,MUIM_Notify,MUIA_Pressed,FALSE,
  1522.                 My_App->App,2,MUIM_Application_ReturnID,ID_EDIT);
  1523.         DoMethod(My_App->BT_Create_Pays,MUIM_Notify,MUIA_Pressed,FALSE,
  1524.                 My_App->App,2,MUIM_Application_ReturnID,ID_CREATE_PAYS);
  1525.         DoMethod(My_App->BT_Trajectoire_OK,MUIM_Notify,MUIA_Pressed,FALSE,
  1526.                 My_App->App,2,MUIM_Application_ReturnID,ID_LOAD_TRAJ_OK);
  1527.         DoMethod(My_App->BT_Trajectoire_Cancel,MUIM_Notify,MUIA_Pressed,FALSE,
  1528.                 My_App->WI_Trajectoire,3,MUIM_Set,MUIA_Window_Open,FALSE);
  1529.         DoMethod(My_App->IM_Trajectoire_Choix,MUIM_Notify,MUIA_Pressed,FALSE,
  1530.                 My_App->App,2,MUIM_Application_ReturnID,ID_SELECT_FILE_TRAJ);
  1531.  
  1532.         DoMethod(My_App->CH_LonLat,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,
  1533.                 My_App->CH_LonLat,3,MUIM_WriteLong,MUIV_TriggerValue,&Pref.Flg_Aff_LatLon);
  1534.         DoMethod(My_App->CH_Coord ,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,
  1535.                 My_App->CH_Coord,3,MUIM_WriteLong,MUIV_TriggerValue,&Pref.Flg_Aff_Coord);
  1536.         DoMethod(My_App->CH_Lacs  ,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,
  1537.                 My_App->CH_Lacs,3,MUIM_WriteLong,MUIV_TriggerValue,&Pref.Flg_Draw_Lac);
  1538.         DoMethod(My_App->CH_Riv   ,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,
  1539.                 My_App->CH_Riv,3,MUIM_WriteLong,MUIV_TriggerValue,&Pref.Flg_Draw_Riv);
  1540.         DoMethod(My_App->CH_Noms  ,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,
  1541.                 My_App->CH_Noms,3,MUIM_WriteLong,MUIV_TriggerValue,&Pref.Flg_Aff_Country_Name);
  1542.         DoMethod(My_App->CH_Fill_Pays  ,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,
  1543.                 My_App->CH_Fill_Pays   ,3,MUIM_WriteLong,MUIV_TriggerValue,&Pref.Flg_Fill_Country);
  1544.         DoMethod(My_App->CH_Elements  ,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,
  1545.                 My_App->CH_Elements   ,3,MUIM_WriteLong,MUIV_TriggerValue,&Pref.Flg_Aff_Elem_Rem);
  1546.         DoMethod(My_App->CH_Trajectoires  ,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,
  1547.                 My_App->CH_Trajectoires   ,3,MUIM_WriteLong,MUIV_TriggerValue,&Pref.Flg_Aff_Trajectoires);
  1548.         DoMethod(My_App->CH_Distance  ,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,
  1549.                 My_App->CH_Distance   ,3,MUIM_WriteLong,MUIV_TriggerValue,&Pref.Flag_Distance);
  1550.         DoMethod(My_App->CH_Scale  ,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,
  1551.                 My_App->CH_Scale   ,3,MUIM_WriteLong,MUIV_TriggerValue,&Pref.Flag_Echelle);
  1552.         DoMethod(My_App->CH_Area  ,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,
  1553.                 My_App->CH_Area   ,3,MUIM_WriteLong,MUIV_TriggerValue,&Pref.Flag_Surface);
  1554.                 
  1555. /*        DoMethod(My_App->BT_Cmd_Panel,MUIM_Notify,MUIA_Pressed,FALSE,
  1556.                 My_App->WI_Cmd_Panel,3,MUIM_Set,MUIA_Window_Open,TRUE);*/
  1557.  
  1558.         DoMethod(My_App->LV_Pays,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,
  1559.                 My_App->App,2,MUIM_Application_ReturnID,ID_NEW_CTY);
  1560.         DoMethod(My_App->LV_Continent  ,MUIM_List_Insert,cont_name,-1,
  1561.                 MUIV_List_Insert_Bottom);
  1562.         DoMethod(My_App->LV_Continent, MUIM_Notify,MUIA_Listview_SelectChange,TRUE,
  1563.                 My_App->App,2,MUIM_CallHook,&continent_select_hook);
  1564.         DoMethod(My_App->LV_Continent, MUIM_List_Select,MUIV_List_Select_All,
  1565.                 MUIV_List_Select_On,NULL);
  1566.         
  1567.         DoMethod(My_App->LV_Elements,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,
  1568.                 My_App->App,2,MUIM_Application_ReturnID,ID_INFO_ELEM);
  1569. /*      DoMethod(My_App->RA_Proj,MUIM_Notify,MUIA_Radio_Active,MUIV_EveryTime,
  1570.                 My_App->App,2,MUIM_Application_ReturnID,ID_PROJ);*/
  1571.  
  1572. /*
  1573.         DoMethod(My_App->PC_Pref_Pages,MUIM_Notify,MUIA_Cycle_Active,MUIV_EveryTime,
  1574.             My_App->App,2,MUIM_Application_ReturnID,ID_GROUPE_CHG);
  1575. */
  1576.  
  1577.         DoMethod(My_App->SL_x,MUIM_Notify,MUIA_Slider_Level,MUIV_EveryTime,
  1578.                 My_App->App,2,MUIM_Application_ReturnID,ID_PR_X);
  1579.         DoMethod(My_App->SL_y,MUIM_Notify,MUIA_Slider_Level,MUIV_EveryTime,
  1580.                 My_App->App,2,MUIM_Application_ReturnID,ID_PR_Y);
  1581.         DoMethod(My_App->SL_z,MUIM_Notify,MUIA_Slider_Level,MUIV_EveryTime,
  1582.                 My_App->App,2,MUIM_Application_ReturnID,ID_PR_Z);
  1583.  
  1584. /*        DoMethod(My_App->IM_Load_Data_Ext,MUIM_Notify,MUIA_Pressed,FALSE,
  1585.                 My_App->App,2,MUIM_Application_ReturnID,ID_SELECT_FILE);
  1586. */
  1587.         DoMethod(My_App->BT_Redraw_Ext_Data,MUIM_Notify,MUIA_Pressed,FALSE,
  1588.                 My_App->App,2,MUIM_Application_ReturnID,ID_REDRAW_EXT);
  1589.  
  1590.         DoMethod(My_App->BT_Redraw,MUIM_Notify,MUIA_Pressed,FALSE,
  1591.                 My_App->App,2,MUIM_Application_ReturnID,ID_REDRAW);
  1592.  
  1593.         DoMethod(My_App->BT_Effacer_Fond,MUIM_Notify,MUIA_Pressed,FALSE,
  1594.                 My_App->App,2,MUIM_Application_ReturnID,ID_NO_FOND);
  1595.  
  1596.         DoMethod(My_App->BT_voir_donnee_externe,MUIM_Notify,MUIA_Pressed,FALSE,
  1597.                 My_App->App,2,MUIM_CallHook,&aff_donnee_externe_hook);
  1598.  
  1599.         set(My_App->TX_nom_element,MUIA_Text_PreParse,"\0333");
  1600.         set(My_App->TX_pays_element,MUIA_Text_PreParse,"\0333");
  1601.  
  1602. /*
  1603.         DoMethod(My_App->BT_Param_3D,MUIM_Notify,MUIA_Pressed,FALSE,
  1604.                 My_App->WI_Param_3D,3,MUIM_Set,MUIA_Window_Open,TRUE);
  1605. */
  1606.         DoMethod(My_App->BT_Vers_Deselect,MUIM_Notify,MUIA_Pressed,FALSE,
  1607.                 My_App->App,2,MUIM_Application_ReturnID,ID_DESELECT);
  1608.  
  1609.         DoMethod(My_App->BT_Vers_Select,MUIM_Notify,MUIA_Pressed,FALSE,
  1610.                 My_App->App,2,MUIM_Application_ReturnID,ID_SELECT);
  1611.  
  1612.         DoMethod(My_App->BT_Continent,MUIM_Notify,MUIA_Pressed,FALSE,
  1613.                 My_App->App,2,MUIM_CallHook,&Classement_Continent_hook);
  1614.  
  1615.         DoMethod(My_App->BT_Tout_Sel,MUIM_Notify,MUIA_Pressed,FALSE,
  1616.                 My_App->App,2,MUIM_CallHook,&Tout_Selectionner_hook);
  1617.  
  1618.         DoMethod(My_App->BT_Tout_Des,MUIM_Notify,MUIA_Pressed,FALSE,
  1619.                 My_App->App,2,MUIM_CallHook,&Tout_Deselectionner_hook);
  1620.  
  1621.         DoMethod(My_App->BT_Petits_Pays,MUIM_Notify,MUIA_Pressed,FALSE,
  1622.                 My_App->App,2,MUIM_CallHook,&Petits_Pays_hook);
  1623.  
  1624.         DoMethod(My_App->BT_Ok_Datas,MUIM_Notify,MUIA_Pressed,FALSE,
  1625.                 My_App->App,2,MUIM_Application_ReturnID,ID_OK_DATAS);
  1626.  
  1627.         DoMethod(My_App->BT_Editer,MUIM_Notify,MUIA_Pressed,FALSE,
  1628.                 My_App->WI_Param_Datas,3,MUIM_Set,MUIA_Window_Open,TRUE);
  1629.  
  1630.         DoMethod(My_App->IM_Fichier_Donnee,MUIM_Notify,MUIA_Pressed,FALSE,
  1631.                 My_App->App,2,MUIM_Application_ReturnID,ID_SELECT_FILE_DONNEE);
  1632.  
  1633.         DoMethod(My_App->BT_Ajouter_Donnee,MUIM_Notify,MUIA_Pressed,FALSE,
  1634.                 My_App->App,2,MUIM_Application_ReturnID,ID_ADD_DATA);
  1635.  
  1636. /*          DoMethod(My_App->WI_Param_3D,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  1637.                 My_App->WI_Param_3D,3,MUIM_Set,MUIA_Window_Open,FALSE);
  1638.  
  1639. DoMethod(My_App->WI_Donnees,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  1640.         My_App->App,2,MUIM_Application_ReturnID,ID_AFF_DONNEES);
  1641. */
  1642.         set(My_App->LV_classement,MUIA_List_Format,",,");
  1643.         set(My_App->LV_classement,MUIA_List_DisplayHook,
  1644.                         &LV_classement_Display_hook);
  1645.         set(My_App->LV_classement,MUIA_List_DestructHook,
  1646.                         &LV_classement_Destruct_hook);
  1647.         DoMethod(My_App->LV_classement,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,
  1648.                 My_App->App,2,MUIM_Application_ReturnID,ID_CLASSEMENT_CTY);
  1649.         Flg_MUI_Initiated=TRUE;
  1650.     }
  1651.     set(My_App->WI_Cmd,MUIA_Window_Open,(APTR)TRUE);
  1652. }
  1653.  
  1654. void Close_Windows(void)
  1655. {
  1656.     int     i;
  1657.  
  1658.     /*printf("%lx %lx\n",My_App->WI_Cmd,*(APTR *)((char *)My_App+Tab_Win[0]));*/
  1659.     for (i=0;Tab_Win[i]!=-1;i++)
  1660.     {
  1661.         set(*(APTR *)((char *)My_App+Tab_Win[i]),MUIA_Window_Open,(APTR)FALSE);
  1662.     }
  1663.  
  1664.     if (MyMenu)
  1665.     {
  1666.         ClearMenuStrip(wG);
  1667.         FreeMenus(MyMenu);
  1668.         MyMenu=NULL;
  1669.     }
  1670.     if (win_info!=0)
  1671.         CloseWindow(win_info);
  1672.     win_info=NULL;
  1673.     signal_win_info=0;
  1674.     if (win_localisation!=0)
  1675.         CloseWindow(win_localisation);
  1676.     win_localisation=NULL;
  1677.     signal_win_localisation=0;
  1678.     if (WI_Drapeaux!=NULL)
  1679.         Do_Action((int)ID_CLOSE_DRAP);
  1680.     if(wG!=0)
  1681.     {
  1682.         if(buffer_rast!=NULL)
  1683.             FreeRaster(buffer_rast,wG->Width,wG->Height+wG->TopEdge);
  1684.         buffer_rast=NULL;
  1685.         CloseWindow(wG);
  1686.     }
  1687. }
  1688.  
  1689.         
  1690. /****************** init_screen **********************/
  1691. BOOL
  1692. Init_Screen(BOOL FirstTime)
  1693. {
  1694.     struct  Screen  *New_sC,*Old_sC;
  1695.     BOOL    Flg_Err;
  1696.     int     Etape;
  1697.  
  1698.     Flg_Err=FALSE;
  1699.     Etape=0;
  1700.  
  1701.     while((Etape<7)&&(Flg_Err==FALSE))
  1702.     {
  1703.         switch(Etape)
  1704.         {
  1705.         case 0:
  1706.             /* Ouverture d'un nouvel ecran  */
  1707.             /*                              */
  1708.             if (FirstTime==TRUE)
  1709.             {
  1710.                 struct Screen * workbench=LockPubScreen("Workbench");
  1711.                 New_sC = OpenScreenTags(        NULL,
  1712.                         SA_Depth    , (ULONG) Pref.Depth     ,
  1713.                 /*        SA_Overscan , Pref.OScan,  */
  1714.                         SA_DisplayID, GetVPModeID(&(workbench->ViewPort)) ,
  1715.                         SA_Pens     ,(ULONG)Tab_Pens,
  1716.                         TAG_DONE);
  1717.                 UnlockPubScreen("Workbench",workbench);
  1718.             }
  1719.             else
  1720.             {       
  1721.                 New_sC = OpenScreenTags(        NULL,
  1722.                         SA_Depth    , (ULONG) Pref.Depth     ,
  1723.           /*              SA_Overscan , Pref.OScan,  */
  1724.                         SA_DisplayID, Pref.DisplayId  ,
  1725.                         SA_Pens     ,(ULONG)Tab_Pens,
  1726.                         TAG_DONE
  1727.                 );
  1728.             }
  1729.             /* Si l'ecran a pu etre ouvert */
  1730.             /* sinon on garde l'ancien    */
  1731.  
  1732.             if(New_sC!=NULL)
  1733.             {
  1734.                 /* on le prend comme nouvel ecran */
  1735.                 Old_sC=sC;
  1736.                 sC=New_sC;
  1737.                 /* il faut vider la queue de messages sans prendre 
  1738.                                 en compte */
  1739.                 Prise_En_Compte=FALSE;
  1740.             };
  1741.             if (sC==NULL)
  1742.                 Flg_Err=TRUE;
  1743.             break;
  1744.         case 1:
  1745.  
  1746.             /* Ferme les fenetres eventuellement ouvertes     */
  1747.             /* et on libere les ressources (rastport, etc...) */
  1748.  
  1749.             Close_Windows();
  1750.  
  1751.             /*NewWindowStructure1.Screen = sC;*/
  1752.             Pref.Width=sC->Width;
  1753.             Pref.Height=sC->Height;
  1754.             Pref.Depth=sC->BitMap.Depth;
  1755.             wG=OpenWindowTags(
  1756.                     NULL,
  1757.                     WA_Left,        0,
  1758.                     WA_Top,         0,
  1759.                     WA_Width,       sC->Width,
  1760.                     WA_Height,      sC->Height,
  1761.                     WA_CustomScreen,sC,
  1762.                     WA_MinWidth,    20L,
  1763.                     WA_MinHeight,   20L,
  1764.                     WA_MaxWidth,    -1,
  1765.                     WA_MaxHeight,   -1,
  1766.                     WA_Flags,       WFLG_BACKDROP|WFLG_REPORTMOUSE|
  1767.                         WFLG_BORDERLESS|WFLG_ACTIVATE|WFLG_NOCAREREFRESH,
  1768.                     WA_IDCMP,       IDCMP_MOUSEBUTTONS|IDCMP_MOUSEMOVE|
  1769.                         /*IDCMP_GADGETUP|IDCMP_GADGETDOWN|*/IDCMP_MENUPICK|
  1770.                         IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_RAWKEY,
  1771.                     TAG_DONE);
  1772.             vP = &sC->ViewPort;
  1773.             /*NewWindowStructure1.Height=sC->Height-NewWindowStructure1.TopEdge;
  1774.             NewWindowStructure1.Width =sC->Width;
  1775.             wG=OpenWindow(&NewWindowStructure1);
  1776.             */
  1777.  
  1778.             if(wG==NULL)Flg_Err=TRUE;
  1779.             break;
  1780.         case 2:
  1781.             Init_Notification();
  1782.             if(Old_sC!=NULL)CloseScreen(Old_sC);
  1783.             break;
  1784.         case 3:
  1785.             {
  1786.                APTR *MyVisualInfo;
  1787.  
  1788.                MyVisualInfo=GetVisualInfo(sC,TAG_END);
  1789.                if (MyVisualInfo)
  1790.                 {
  1791.                     MyMenu=CreateMenus(Menu,TAG_END);
  1792.                     if (MyMenu)
  1793.                     {
  1794.                         LayoutMenus(MyMenu,MyVisualInfo,TAG_END);
  1795.                         SetMenuStrip(wG,MyMenu);
  1796.                     }
  1797.                     else
  1798.                         Flg_Err=TRUE;
  1799.                     FreeVisualInfo(MyVisualInfo);       
  1800.                 }
  1801.                 else
  1802.                     Flg_Err=TRUE;
  1803.             }
  1804.             break;
  1805.         case 4:
  1806.             Map_Set_Default_Colors(vP);
  1807.  
  1808.             rpG = wG->RPort;
  1809.             signal_wG=(1<<wG->UserPort->mp_SigBit);
  1810.  
  1811.             give_size_window(wG->Width,wG->Height);
  1812.             /* Window 2 */
  1813.     
  1814.             buffer_rast=(char *)AllocRaster(wG->Width,wG->Height+wG->TopEdge);
  1815.             /*buffer_rast=(char *)AllocRaster(Pref.Width,Pref.Height);*/
  1816.             if  (buffer_rast==NULL)
  1817.             {
  1818.                 printf("Error allocating buffer!\n");
  1819.                 Flg_Err=TRUE;
  1820.             }
  1821.             break;
  1822.         case 5:
  1823.             InitArea(&myareainfo,areabuffer,MAX_AREA_PT);
  1824.             rpG->AreaInfo=&myareainfo;
  1825.             InitTmpRas(&tmpras,buffer_rast,RASSIZE(wG->Width,wG->Height+wG->TopEdge));
  1826.             rpG->TmpRas=&tmpras;
  1827.             if(rpG->TmpRas==NULL)Flg_Err=TRUE;
  1828.             break;
  1829.         default:
  1830.             break;
  1831.         }
  1832.         Etape++;
  1833.     }
  1834.     return(Flg_Err);
  1835. }
  1836.  
  1837. /***********************************************************************/
  1838. /*  display et compare hooks pour les listes MUI                       */
  1839. /***********************************************************************/
  1840.  
  1841. void
  1842. SAVEDS ASM LV_Pays_Display_func(REG(a2) char **array,REG(a1) COUNTRY * pays)
  1843. {
  1844.     array[0]=strdup(pays->name);
  1845.     array[1]=strdup(pays->name);
  1846. }
  1847.  
  1848. struct Hook LV_Pays_Display_hook=
  1849. {
  1850.     {NULL,NULL},
  1851.     (void *)LV_Pays_Display_func,
  1852.     NULL,NULL
  1853. };
  1854.  
  1855. SAVEDS ASM LONG LV_Pays_Compare_func(REG(a1) COUNTRY *pays1,REG(a2) COUNTRY * pays2)
  1856.  
  1857. {
  1858.     return stricmp(pays1->name,pays2->name);
  1859. }
  1860.  
  1861. struct Hook LV_Pays_Compare_hook=
  1862. {
  1863.     {NULL,NULL},
  1864.     LV_Pays_Compare_func,
  1865.     NULL,NULL
  1866. };
  1867.  
  1868.  
  1869. /*********************************************************** main() ****/
  1870.  
  1871. main( int argc,  char **argv   )
  1872. {
  1873.         char    *name;
  1874.         int     Etape;
  1875.         BOOL    Flg_Err;
  1876.  
  1877.         Flg_Err=FALSE;
  1878.         Etape=0;
  1879.  
  1880.         /* Initialisation .                             */
  1881.         /* Il y a un certian nombre d'etape. Si chaque  */
  1882.         /* etape s'est initialisee correctement, on     */
  1883.         /* passe a la suivante. Sinon, on sort et on    */
  1884.         /* libere les ressources                        */
  1885.  
  1886.         while((Etape<17)&&(Flg_Err==FALSE)){
  1887.  
  1888.            switch(Etape){
  1889.             case 0:
  1890.                     IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0);
  1891.                     if (IntuitionBase == NULL)
  1892.                     {
  1893.                             printf("intuition is not here.  where are we?\n");
  1894.                             Flg_Err=TRUE;
  1895.                     }
  1896.                     GfxBase      = (struct GfxBase *)OpenLibrary("graphics.library", 0);
  1897.                     DiskfontBase = OpenLibrary("diskfont.library", 37L);
  1898.                     GadToolsBase = OpenLibrary("gadtools.library", 37L);
  1899.                     AslBase=(struct Library *)OpenLibrary(AslName,0);
  1900.                     /* ce n'est pas grave si la librairie fastsincos n'est pas la*/
  1901.                     FastsincosBase=(struct Library *)OpenLibrary("fastsincos.library",0);
  1902.                     if (FastsincosBase==NULL)
  1903.                         printf("Warning: Fastsincos library is not here\n");
  1904.                     if (GfxBase->LibNode.lib_Version>=39)
  1905.                     {
  1906.                         /* nous en sommes en Workbench 3.0 ou + */
  1907.                         DataTypeBase = OpenLibrary ("datatypes.library", 39L);
  1908.                         LocaleBase=OpenLibrary("locale.library",38L);
  1909.                         if (LocaleBase!=NULL)
  1910.                             MyLocale=OpenLocale(NULL);
  1911.                     }
  1912.                     break;
  1913.             case 1:
  1914.  
  1915.                 /* allocation mémoire tableaux tab_vect et tab_country */
  1916.                     init_map_datas();
  1917.                     /*initialisation des valeurs de Pref*/
  1918.                     init_preference();
  1919.                     break;
  1920.             case 2:
  1921.  
  1922.                     init();                 /* Mui function */
  1923.                     break;
  1924.  
  1925.             case 5:
  1926.                     My_App=CreateApp();
  1927.  
  1928.                     if (!My_App->App) Flg_Err=TRUE;
  1929.                     break;
  1930.             
  1931.             case 6:
  1932.                     areabuffer=AllocMem(MAX_AREA_PT*5,0L);
  1933.                     //areabuffer=(WORD *)malloc(MAX_AREA_PT*5*sizeof(WORD));
  1934.                     if(areabuffer==NULL)Flg_Err=TRUE;
  1935.                     break;
  1936.             case 7:
  1937.                     {
  1938.                     srand(time(NULL));
  1939.                     if (load_preference()==FALSE)
  1940.                     {
  1941.                             /*printf("impossible de charger les préférences!\n");*/
  1942.                             /* Ouverture des ecrans et fenetres */
  1943.                             Flg_Err=Init_Screen(TRUE);
  1944.                     }
  1945.                     else
  1946.                     {
  1947.                         /* init screen                          */
  1948.                         if (Init_Screen(FALSE)==TRUE)
  1949.                             Flg_Err=Init_Screen(TRUE);
  1950.                         else
  1951.                             Flg_Err=FALSE;
  1952.                         /* initialisation des paramètres vue 3D */
  1953.                         /* il faut que wG existe                */
  1954.                         cmd_new_3d();
  1955.                     }
  1956.                     }
  1957.                     break;
  1958.             case 8:
  1959.                 {
  1960.                     /* affichage ecran d'intro*/
  1961.                     ULONG modeID = LORES_KEY;
  1962.                     DisplayInfoHandle displayhandle;
  1963.                     struct DimensionInfo dimensioninfo;
  1964.                     if ((displayhandle=FindDisplayInfo(modeID))!=NULL)
  1965.                         if (GetDisplayInfoData(displayhandle,(UBYTE *) &dimensioninfo,
  1966.                             sizeof(struct DimensionInfo),DTAG_DIMS,NULL)!=0)
  1967.                             if (dimensioninfo.MaxDepth>=8)
  1968.                                 /* mode AGA ? (on peut afficher l'image)*/
  1969.                                 sC_Image=Iff_Load_And_Open("intro");
  1970.                             else
  1971.                                 /* mode ECS */
  1972.                                 sC_Image=Iff_Load_And_Open("intro8");
  1973.                     if (rand()>RAND_MAX/2)
  1974.                             sprintf(Titre_Ecran,"Amiglobe   (C)1994 by %s & %s",
  1975.                                             "Olivier Collard","Thomas Landspurg");
  1976.                     else
  1977.                             sprintf(Titre_Ecran,"Amiglobe   (C)1994 by %s & %s",
  1978.                                             "Thomas Landspurg","Olivier Collard");
  1979.                     SetWindowTitles(wG,(UBYTE *)~0,Titre_Ecran );
  1980.  
  1981.                     /*
  1982.                             SetMenuStrip(wG,&MenuList1);
  1983.                     */
  1984.                     
  1985.                     /*cmd_warning();*//* affichage blabla */
  1986.                 }
  1987.                     break;
  1988.             case 9:
  1989.  
  1990.                     IPrint(rpG,10,wG->Height/2,"Loading Data, Please Wait....",-1);
  1991.  
  1992.                     if(argc<2)
  1993.                     {
  1994.                             name="new_lac";
  1995.                     }
  1996.                     else
  1997.                     {
  1998.                             name=argv[1];
  1999.                     }
  2000.                     /*IPrint(rpG,10,wG->Height/2+20,"Reading Points..",-1);*/
  2001.                     Flg_Err=read_map_bin(name);
  2002.                     break;
  2003.             case 10:
  2004.                     /*IPrint(rpG,10,wG->Height/2+40,"Reading Zones...",-1);*/
  2005.                     Flg_Err=read_zones(name,rpG);
  2006.                     break;
  2007.             case 11:
  2008.                     /*IPrint(rpG,10,wG->Height/2+60,"Reading Infos..",-1);*/
  2009.                     Flg_Err=read_database(name);
  2010.                     break;
  2011.             case 12:
  2012.                     /*IPrint(rpG,10,wG->Height/2+80,"Reading Statistics..",-1);
  2013.                     Flg_Err=Dtb_Read_Stats();
  2014.                     Dtb_Create_Liste_Data(My_App->LV_Datas);
  2015.                     Dtb_Create_Liste_Data(My_App->LV_Data1);
  2016.                     Dtb_Create_Liste_Data(My_App->LV_Data2);*/
  2017.                     break;
  2018.             case 13:
  2019.                     Main_Init_Font();
  2020.                     break;
  2021.             case 14:
  2022.                 /* Cree la liste des pays a inserer dans les listes utilisant */
  2023.                 /* les pays                                             */
  2024.                 {
  2025.                    int  max_country=get_max_country();
  2026.                    COUNTRY * pays;
  2027.                    int i;
  2028.                     set(My_App->LV_Pays,MUIA_List_CompareHook,
  2029.                         &LV_Pays_Compare_hook);
  2030.                     set(My_App->LV_Pays,MUIA_List_DisplayHook,
  2031.                         &LV_Pays_Display_hook);
  2032.                     set(My_App->LV_Select,MUIA_List_CompareHook,
  2033.                         &LV_Pays_Compare_hook);
  2034.                     set(My_App->LV_Select,MUIA_List_DisplayHook,
  2035.                         &LV_Pays_Display_hook);
  2036.                     set(My_App->LV_Deselect,MUIA_List_CompareHook,
  2037.                         &LV_Pays_Compare_hook);
  2038.                     set(My_App->LV_Deselect,MUIA_List_DisplayHook,
  2039.                         &LV_Pays_Display_hook);
  2040.                     for(i=0;i<max_country;i++)
  2041.                     {
  2042.                         pays=&(tab_country[i]);
  2043.                         DoMethod(My_App->LV_Pays,MUIM_List_Insert,
  2044.                             &pays,1,MUIV_List_Insert_Sorted);
  2045.                         DoMethod(My_App->LV_Select,MUIM_List_Insert,
  2046.                             &pays,1,MUIV_List_Insert_Sorted);
  2047.                     }
  2048.                     if (Pref.country_sel!=-1)
  2049.                         set(My_App->TX_Selectionne,MUIA_Text_Contents,
  2050.                             tab_country[Pref.country_sel].name);
  2051.  
  2052.                 }
  2053.                 break;
  2054.             case 15:
  2055.                 if (Pref.point_orig.existe==TRUE
  2056.                     && Pref.point_dest.existe==TRUE)
  2057.                     distance_orig_dest=distance(
  2058.                         Pref.point_orig.longitude,
  2059.                         Pref.point_orig.latitude,
  2060.                         Pref.point_dest.longitude,
  2061.                         Pref.point_dest.latitude);
  2062.                 break;
  2063.  
  2064.             case 16:
  2065.             /*ScreenToFront(sC);*/
  2066.                     /* effacement de l'ecran d'intro*/
  2067.                     if (sC_Image) Del_Ext_Image();
  2068.                     break;  
  2069.             default:
  2070.                     break;
  2071.             }
  2072.            Etape++;
  2073.            /*printf("Etape:%d\n",Etape);*/
  2074.         
  2075.         }
  2076.         if(Flg_Err==FALSE){
  2077.                 cmd_redraw();
  2078.                 main_loop();
  2079.         }
  2080.         
  2081.         
  2082.         /* Liberation des ressources */
  2083.         Close_Windows();
  2084.         /*printf("disposeapp\n");*/
  2085.         if(My_App)DisposeApp(My_App);
  2086.         Dispose_Organisation();
  2087.         /*printf("disposescreen\n");*/
  2088.         if(sC!=0)CloseScreen(sC);
  2089.         sC=NULL;
  2090.         /*printf("del image \n");*/
  2091.         Del_Image();
  2092.         /*printf("del ext image \n");*/
  2093.         Del_Ext_Image();
  2094.         /*printf("free map data\n");*/
  2095.         free_map_datas();
  2096.         /*printf("close libraries\n");*/
  2097.         if (AslBase              ) CloseLibrary(AslBase);
  2098.         if (DiskfontBase         ) CloseLibrary(DiskfontBase);
  2099.         if (GadToolsBase         ) CloseLibrary(GadToolsBase);
  2100.         if (GfxBase != NULL      ) CloseLibrary((struct Library *)GfxBase);
  2101.         if (IntuitionBase != NULL) CloseLibrary((struct Library *)IntuitionBase);
  2102.         if (MUIMasterBase        ) CloseLibrary(MUIMasterBase);
  2103.         if (DataTypeBase         ) CloseLibrary(DataTypeBase);
  2104.         if (FastsincosBase       ) CloseLibrary(FastsincosBase);
  2105.         /* sauvegarde des préférences */
  2106.         if (save_preference()==FALSE)
  2107.                 {}
  2108.                 /*printf("impossible de sauver les préférences!\n");*/
  2109.         return(0);
  2110.         
  2111. }
  2112.  
  2113.  
  2114. void Main_Print_Deg(struct RastPort *rpG,int x,int y,int val1,int val2)
  2115. {
  2116.         char    buffer[100];
  2117.         char east,north;
  2118.         int     deg1=ABS(val1/100);
  2119.         int min1=(ABS(val1)%100)*60/100;
  2120.         int     deg2=ABS(val2/100);
  2121.         int min2=(ABS(val2)%100)*60/100;
  2122.         if (val1<0)
  2123.                 east='W';
  2124.         else
  2125.                 east='E';
  2126.         if (val2<0)
  2127.                 north='S';
  2128.         else
  2129.                 north='N';
  2130.  
  2131.         
  2132.         sprintf(buffer,"%d°%02d'%c   ",deg1,min1,east);
  2133.         set(My_App->TX_lon,MUIA_Text_Contents,buffer);
  2134. /*      IPrint(rpG,x,y,buffer,-1);*/
  2135.         sprintf(buffer,"%d°%02d'%c   ",deg2,min2,north);
  2136.         set(My_App->TX_lat,MUIA_Text_Contents,buffer);  
  2137. /*      IPrint(rpG,x+200,y,buffer,-1);*/
  2138.         
  2139. }
  2140.  
  2141.  
  2142. void mouse_action(int x,int y,ULONG class,UWORD code)
  2143. {
  2144.    static       int     new_pays,old_pays=-1;
  2145.    static       int     old_x,old_y;
  2146.    static       int     start_zx,start_zy;
  2147.    /*int old_country;*/
  2148.  
  2149.    char buffer[100]     ;
  2150.  
  2151.    switch (class)
  2152.    {
  2153.     case MOUSEBUTTONS:
  2154.         if(code == SELECTDOWN)
  2155.         {
  2156.             switch (action)
  2157.             {
  2158.             case CMD_SELECT:
  2159.                 cmd_new_cty(find_country(x,y));
  2160.                 /*
  2161.                 old_country=Pref.country_sel;
  2162.                 if (old_country!=-1)
  2163.                 {
  2164.                     fill_country(Pref.country_sel,0,rpG);
  2165.                 }
  2166.                 Pref.country_sel=find_country(x,y);
  2167.                 if (Pref.country_sel==old_country) /* déselection d'un pays*/
  2168.                 /*{
  2169.                     set(My_App->TX_Selectionne,MUIA_Text_Contents,
  2170.                         0);
  2171.                     Pref.country_sel=-1;
  2172.                 }
  2173.                 else
  2174.                 {
  2175.                     if (Pref.country_sel!=-1)
  2176.                     {
  2177.                         set(My_App->TX_Selectionne,MUIA_Text_Contents,
  2178.                             get_pays_name(Pref.country_sel));
  2179.                         fill_country(Pref.country_sel,1,rpG);
  2180.                         if (win_info!=NULL)
  2181.                             cmd_info();
  2182.                     }
  2183.                 }  */
  2184.                     break;
  2185.             case CMD_NEW_POINT:
  2186.             {
  2187.                 int code;
  2188.                 conv_inv_xy(&x,&y);
  2189.                 tab_new_border[longueur_new_border*3+1]=x;
  2190.                 tab_new_border[longueur_new_border*3+2]=y;
  2191.                 if (longueur_new_border==0)
  2192.                 {
  2193.                         char * buffer;
  2194.                 get(My_App->STR_Code,MUIA_String_Contents,(APTR)&buffer);
  2195.                         code=atoi(buffer);
  2196.                 }
  2197.                 else
  2198.                 {
  2199.                 get(My_App->SL_Code_Point,MUIA_Slider_Level,(APTR)&code);
  2200.                         MyMove(rpG,
  2201.                                 tab_new_border[longueur_new_border*3-2],
  2202.                                 tab_new_border[longueur_new_border*3-1]);
  2203.                         MyDraw(rpG,x,y,code);
  2204.                 }                                       
  2205.                 tab_new_border[longueur_new_border*3]=code;
  2206.                 longueur_new_border++;
  2207.                 /*printf("nouveau point lon=%d lat=%d code=%d nbre de points=%d \n",
  2208.                         x,y,code,longueur_new_border);*/
  2209.             }
  2210.                 break;
  2211.             case CMD_ZOOM:
  2212.                 flg_press=TRUE;
  2213.                 old_x=x;
  2214.                 old_y=y;
  2215.                 start_zx=x;
  2216.                 start_zy=y;
  2217.                 SetDrMd(rpG,COMPLEMENT);
  2218.                 break;
  2219.             case CMD_POINT_ORIG:
  2220.                 conv_inv_xy(&x,&y);
  2221.                 if (point_est_dans(x,y,&clip_max)==TRUE)
  2222.                 {
  2223.                     Pref.point_orig.longitude=x;
  2224.                     Pref.point_orig.latitude=y;
  2225.                     Pref.point_orig.existe=TRUE;
  2226.                     map_aff_point(rpG,&Pref.point_orig,0);
  2227.                     if (Pref.point_dest.existe==TRUE)
  2228.                         distance_orig_dest=distance(
  2229.                         Pref.point_orig.longitude,
  2230.                         Pref.point_orig.latitude,
  2231.                         Pref.point_dest.longitude,
  2232.                         Pref.point_dest.latitude);
  2233.                     Update_Points();
  2234.                     Draw_Chemin(rpG);
  2235.                     if (Pref.Flag_Distance)
  2236.                         aff_distance();
  2237.                     /*reselect(rpG);*/
  2238.                     action=CMD_SELECT;
  2239.                 }
  2240.                 break;
  2241.             case CMD_POINT_DEST:
  2242.                 conv_inv_xy(&x,&y);
  2243.                 if (point_est_dans(x,y,&clip_max)==TRUE)
  2244.                 {
  2245.                     Pref.point_dest.longitude=x;
  2246.                     Pref.point_dest.latitude=y;
  2247.                     Pref.point_dest.existe=TRUE;
  2248.                     map_aff_point(rpG,&Pref.point_dest,1);
  2249.                     if (Pref.point_orig.existe==TRUE)
  2250.                             distance_orig_dest=distance(
  2251.                             Pref.point_orig.longitude,
  2252.                             Pref.point_orig.latitude,
  2253.                             Pref.point_dest.longitude,
  2254.                             Pref.point_dest.latitude);
  2255.                     Update_Points();
  2256.                     Draw_Chemin(rpG);
  2257.                     if (Pref.Flag_Distance)
  2258.                         aff_distance();
  2259.  
  2260.                     /*reselect(rpG);*/
  2261.                     action=CMD_SELECT;
  2262.                 }
  2263.                 break;
  2264.             case CMD_DONN_EXT:
  2265.             {
  2266.                 char buffer[256];
  2267.                 char buffer2[256];
  2268.                 int i;
  2269.                 int distance=100000;
  2270.                 ELEM_REM * element,*sel_element=tab_country[0].P_Elem_Rem;
  2271.                 conv_inv_xy(&x,&y);
  2272.                 for (i=0;i<get_max_country();i++)
  2273.                 {
  2274.                     element=tab_country[i].P_Elem_Rem;
  2275.                     while (element!=NULL)
  2276.                     {
  2277.                         if (iabs(element->Lon-x)+iabs(element->Lat-y)<distance)
  2278.                         {
  2279.                             distance=iabs(element->Lon-x)+iabs(element->Lat-y);
  2280.                             sel_element=element;
  2281.                         }
  2282.                         element=element->P_Next;
  2283.                     }
  2284.                 }
  2285.                 set(My_App->WI_Info_Element,MUIA_Window_Open,TRUE);
  2286.                 set(My_App->TX_nom_element,MUIA_Text_Contents,sel_element->Nom);
  2287.                 switch(sel_element->Type)
  2288.                 {
  2289.                 case CAPITALE:
  2290.                     sprintf(buffer,"is the capital city of ");
  2291.                     Map_Put_Million(buffer2,"Population:%s hab",sel_element->caracteristique);
  2292.                     break;
  2293.                 case VILLE:
  2294.                     sprintf(buffer,"is a city of ");
  2295.                     Map_Put_Million(buffer2,"Population:%s hab",sel_element->caracteristique);
  2296.                     break;
  2297.                 case MONTAGNE:
  2298.                     sprintf(buffer,"is a mountain of ");
  2299.                     Map_Put_Million(buffer2,"Altitude:%s m",sel_element->caracteristique);
  2300.                     break;
  2301.                 case MONUMENT:
  2302.                     sprintf(buffer,"is a monument of ");
  2303.                     if (sel_element->caracteristique>50)
  2304.                             sprintf(buffer2,"Very interesting");
  2305.                     else
  2306.                             sprintf(buffer2,"Less interesting");
  2307.                     break;
  2308.                 }
  2309.                 set(My_App->TX_type_element,MUIA_Text_Contents,buffer);
  2310.                 i=pays(sel_element);
  2311.                 if (i!=-1)
  2312.                         set(My_App->TX_pays_element,MUIA_Text_Contents,
  2313.                                         tab_country[i].name);                           
  2314.                 sprintf(buffer,"%d°%d'",-(sel_element->Lat)/100,
  2315.                         iabs((sel_element->Lat%100)*60/100));
  2316.                 set(My_App->TX_latitude_element,MUIA_Text_Contents,buffer);
  2317.                 sprintf(buffer,"%d°%d'",(sel_element->Lon)/100,
  2318.                         iabs((sel_element->Lon%100)*60/100));
  2319.                 set(My_App->TX_longitude_element,MUIA_Text_Contents,buffer);
  2320.                 set(My_App->TX_caracteristique_element,MUIA_Text_Contents,buffer2);
  2321.                 if (fopen(sel_element->Nom,"r")==NULL)
  2322.                     set(My_App->BT_voir_donnee_externe,MUIA_Disabled,TRUE);
  2323.                 else
  2324.                     set(My_App->BT_voir_donnee_externe,MUIA_Disabled,FALSE);
  2325.                 ActivateWindow(wG);
  2326.                 action=CMD_SELECT;
  2327.             }
  2328.             break;
  2329.             }/* End of switch/case sur cmd */
  2330.  
  2331.         }
  2332.         else
  2333.         if ( code == SELECTUP )
  2334.         {
  2335.             switch (action)
  2336.             {
  2337.             case CMD_ZOOM:
  2338.                 y=(x-start_zx)*wG->Height/wG->Width+start_zy;
  2339.                 if((x!=start_zx)&&(y!=start_zy))
  2340.                 {
  2341.                     map_set_zoom(rpG,start_zx,start_zy,x,y);
  2342.                 }
  2343.                 flg_press=FALSE;
  2344.                 action = CMD_SELECT;
  2345.                 Pref.Flg_Aff_Coord=TRUE;
  2346.             break;
  2347.             }
  2348.         }
  2349.         break;
  2350.  
  2351.         case MOUSEMOVE :
  2352.  
  2353.             switch (action)
  2354.             {
  2355.             case CMD_NEW_POINT:
  2356.             case CMD_POINT_ORIG:
  2357.             case CMD_POINT_DEST:
  2358.             case CMD_DONN_EXT:
  2359.             case CMD_SELECT:
  2360.                 if (Pref.Flg_Aff_Coord)
  2361.                  {
  2362.                     new_pays=find_country(x,y);
  2363.                     if (new_pays!=old_pays)
  2364.                     {
  2365.                         if (new_pays!=-1)
  2366.                         {
  2367.                             set (My_App->TX_courant,MUIA_Text_Contents,
  2368.                                     get_pays_name(new_pays));
  2369.                         }
  2370.                         else
  2371.                         set (My_App->TX_courant,MUIA_Text_Contents,
  2372.                                     0);
  2373.  
  2374.                         }
  2375.  
  2376.                         conv_inv_xy(&x,&y);
  2377.                         Main_Print_Deg(rpG,300,Text_Font->tf_YSize+2,x,-y);
  2378.                         if ((Pref.Flag_Distance)&&(Pref.point_dest.existe==FALSE)
  2379.                                 &&(Pref.point_orig.existe==TRUE))
  2380.                         {
  2381.                             sprintf(buffer,"Distance: %.6f km  ",distance(x,y,
  2382.                                 Pref.point_orig.longitude,Pref.point_orig.latitude));
  2383.                             IPrint(rpG,8,Text_Font->tf_YSize*2+2,buffer,-1);
  2384.                         }
  2385.                     }
  2386.                     break;
  2387.                       case CMD_ZOOM:
  2388.                                 if (flg_press)
  2389.                 {
  2390.                                         y=(x-start_zx)*wG->Height/wG->Width+start_zy;
  2391.                                         map_draw_rect(rpG,start_zx,start_zy,old_x-start_zx,old_y-start_zy);
  2392.                                         map_draw_rect(rpG,start_zx,start_zy,x-start_zx,y-start_zy);
  2393.                                         old_x=x;
  2394.                                         old_y=y;
  2395.                                 }
  2396.                                 break;
  2397.                 }
  2398.                 break;
  2399.         }/* End of case */
  2400. }
  2401.  
  2402.  
  2403. void Do_Action(int In_Action)
  2404. {
  2405.     int     sel;
  2406.     switch(In_Action)
  2407.     {
  2408.         case MUIV_Application_ReturnID_Quit:
  2409.                 quit();
  2410.                 break;
  2411.         case ID_ABOUT:
  2412.                 cmd_about();
  2413.                 break;
  2414.         case ID_DEFAULT_PREF:
  2415.                 init_preference();
  2416.                 Init_Screen(FALSE);
  2417.                 cmd_redraw();
  2418.                 SetWindowTitles(wG,(UBYTE *)~0,Titre_Ecran );
  2419.                 break;
  2420.         case ID_LOAD_TRAJ:
  2421.                 /*printf("affichage fenetre trajectoire\n");*/
  2422.                 set(My_App->WI_Trajectoire,MUIA_Window_Open,TRUE);
  2423.                 break;
  2424.         case ID_LOAD_TRAJ_OK:
  2425.                 read_trajectoires();
  2426.                 break;
  2427.         case ID_SELECT_FILE_TRAJ:
  2428.                 cmd_select_file(My_App->STR_Trajectoire_Fichier);                       
  2429.                 break;
  2430.         case ID_REDRAW:
  2431.                 cmd_redraw();
  2432.                 break;
  2433.         case ID_INFO:
  2434.                 cmd_info();
  2435.                 break;
  2436.         case ID_FILL:
  2437.                 //cmd_fill();
  2438.                 break;
  2439.         case ID_MOVE_PT:
  2440.                 cmd_move_pt();
  2441.                 break;
  2442.         case ID_SHOW_PT:
  2443.                 cmd_show_pt();
  2444.                 break;
  2445.         case ID_SHOW_SEG:
  2446.                 cmd_show_seg();
  2447.                 break;
  2448. /*              case ID_ZOOM:
  2449.                 cmd_zoom();
  2450.                 break;
  2451.         case ID_ZOOM_RESET:
  2452.                 cmd_zoom_reset();
  2453.                 break;
  2454.         case ID_ZOOM_OUT:
  2455.                 cmd_zoom_out();
  2456.                 break;*/
  2457.         case ID_EDIT:
  2458.                 cmd_edit_pays();
  2459.                 break;
  2460.         case ID_CREATE_PAYS:
  2461.                 cmd_create_pays();
  2462.                 break;
  2463.         case ID_MODE_EDIT:
  2464.                 flg_edit=TRUE;
  2465.                 break;
  2466.         case ID_MODE_NOT_EDIT:
  2467.                 flg_edit=FALSE;
  2468.                 break;
  2469. /*              case ID_NEW_BORDER:
  2470.                 tab_new_border=(short int*)malloc(500);
  2471.                 break;
  2472.         case ID_NEW_POINT:
  2473.                 action=CMD_NEW_POINT;
  2474.                 break;
  2475.         case ID_END_BORDER:
  2476.                 cmd_end_border();
  2477.                 break;*/
  2478.         case ID_SEL_CTY:
  2479.                 cmd_sel_cty();
  2480.                 break;
  2481.         case ID_NEW_CTY:
  2482.              {
  2483.                 int     cty;
  2484.                 COUNTRY * pays;
  2485.                 get(My_App->LV_Pays,MUIA_List_Active,&cty);
  2486.                 DoMethod(My_App->LV_Pays,MUIM_List_GetEntry,cty,&pays);
  2487.                 cmd_new_cty(Dtb_Find_Country_Pos(pays->name));
  2488.              }
  2489.              break;
  2490.         case ID_CLASSEMENT_CTY:
  2491.             {
  2492.                 int cty;
  2493.                 DATA_TRI * donnee;
  2494.                 get(My_App->LV_classement,MUIA_List_Active,&cty);
  2495.                 DoMethod(My_App->LV_classement,MUIM_List_GetEntry,cty,&donnee);
  2496.                 cmd_new_cty(donnee->Num_Pays);
  2497.             }
  2498.             break;
  2499.         case ID_SEL_CONT:
  2500.                 set(My_App->WI_Sel_Cont,MUIA_Window_Open,(APTR)TRUE);
  2501.                 break;
  2502.         case ID_SEL_ELEM:
  2503.                 cmd_sel_elem();
  2504.                         break;
  2505.         case ID_INFO_ELEM:
  2506.                 {
  2507.                 int elem,i;
  2508.                 ELEM_REM * element;
  2509.                 /*char * nom_elem;*/
  2510.                 char buffer[30];
  2511.                 get(My_App->LV_Elements,MUIA_List_Active,&elem);
  2512.                 DoMethod(My_App->LV_Elements,MUIM_List_GetEntry,elem,&element);
  2513.                 if (element==NULL)
  2514.                         break;
  2515.                 set(My_App->TX_Selected_Element,MUIA_Text_Contents,
  2516.                                 element->Nom);
  2517.                 i=pays(element);
  2518.                 if (i!=-1)
  2519.                         set(My_App->TX_Pays,MUIA_Text_Contents,
  2520.                                         tab_country[i].name);                           
  2521.                 sprintf(buffer,"Lat:%d°%d'",-(element->Lat)/100,
  2522.                         iabs((element->Lat%100)*60/100));
  2523.                 set(My_App->TX_Latitude,MUIA_Text_Contents,buffer);
  2524.                 sprintf(buffer,"Lon:%d°%d'",(element->Lon)/100,
  2525.                         iabs((element->Lon%100)*60/100));
  2526.                 set(My_App->TX_Longitude,MUIA_Text_Contents,buffer);
  2527.                 switch (element->Type)
  2528.                 {
  2529.                 case CAPITALE:
  2530.                 case VILLE:
  2531.         Map_Put_Million(buffer,"Pop:%s hab",element->caracteristique);
  2532.                         /*sprintf(buffer,"Pop:%d hab",element->caracteristique);*/
  2533.                         break;
  2534.                 case MONTAGNE:
  2535.         Map_Put_Million(buffer,"Altitude:%s m",element->caracteristique);
  2536.                         /*sprintf(buffer,"Altitude:%d m",element->caracteristique);*/
  2537.                         break;
  2538.                 case MONUMENT:
  2539.                         if (element->caracteristique>50)
  2540.                                 sprintf(buffer,"Very interesting");
  2541.                         else
  2542.                                 sprintf(buffer,"Less interesting");
  2543.                         break;
  2544.                 default:
  2545.                                 sprintf(buffer,"Element type unknown");
  2546.                         break;
  2547.                 }
  2548.                 set(My_App->TX_Caracteristique,MUIA_Text_Contents,buffer);      
  2549.                 free (buffer);
  2550.                 }
  2551.                 break;
  2552.         case ID_ELEM_SET_POINT_ORIG:
  2553.                 {
  2554.                 /*char * nom_elem;*/
  2555.                 int elem;
  2556.                 ELEM_REM * element;
  2557.                 get(My_App->LV_Elements,MUIA_List_Active,&elem);
  2558.                 DoMethod(My_App->LV_Elements,MUIM_List_GetEntry,elem,&element);
  2559.                 Pref.point_orig.longitude=element->Lon;
  2560.                 Pref.point_orig.latitude=element->Lat;
  2561.                 Pref.point_orig.existe=TRUE;
  2562.                 map_aff_point(rpG,&Pref.point_orig,0);
  2563.                 if (Pref.point_dest.existe==TRUE)
  2564.                         distance_orig_dest=distance(
  2565.                         Pref.point_orig.longitude,
  2566.                         Pref.point_orig.latitude,
  2567.                         Pref.point_dest.longitude,
  2568.                         Pref.point_dest.latitude);
  2569.                 Update_Points();
  2570.                 Draw_Chemin(rpG);
  2571.                 }
  2572.                 break;
  2573.         case ID_ELEM_SET_POINT_DEST:
  2574.                 {
  2575.                 /*char * nom_elem;*/
  2576.                 int elem;
  2577.                 ELEM_REM * element;
  2578.                 get(My_App->LV_Elements,MUIA_List_Active,&elem);
  2579.                 DoMethod(My_App->LV_Elements,MUIM_List_GetEntry,elem,&element);
  2580.                 Pref.point_dest.longitude=element->Lon;
  2581.                 Pref.point_dest.latitude=element->Lat;
  2582.                 Pref.point_dest.existe=TRUE;
  2583.                 map_aff_point(rpG,&Pref.point_dest,0);
  2584.                 if (Pref.point_orig.existe==TRUE)
  2585.                         distance_orig_dest=distance(
  2586.                         Pref.point_orig.longitude,
  2587.                         Pref.point_orig.latitude,
  2588.                         Pref.point_dest.longitude,
  2589.                         Pref.point_dest.latitude);
  2590.                 }
  2591.                 Update_Points();
  2592.                 Draw_Chemin(rpG);
  2593.                 break;                                  
  2594.         case ID_NOT_YET:
  2595.                 cmd_not_yet();
  2596.                 break;
  2597.         case ID_AFF_DATA:
  2598.                 cmd_redraw_datas();
  2599.                 break;
  2600.         case ID_AFF_DATA_EXT:
  2601.                 set(My_App->WI_Chargement,MUIA_Window_Open,(APTR)TRUE);
  2602.                 break;
  2603. /*        case ID_SELECT_FILE:
  2604.                         cmd_select_file(My_App->STR_Fichier);   
  2605.                         break;*/
  2606.         case ID_SELECT_FILE_DONNEE:
  2607.                 cmd_select_file(My_App->STR_fichier_Donnee);
  2608.                 break;
  2609.         case ID_REDRAW_EXT:
  2610.                         cmd_redraw_ext();
  2611.                         break;            
  2612.         case ID_DETAIL_ALL:
  2613.                 map_set_prof(0);
  2614.                 break;
  2615.         case ID_DETAIL_1:
  2616.                 map_set_prof(1);
  2617.                 break;
  2618.         case ID_DETAIL_2:
  2619.                 map_set_prof(2);
  2620.                 break;
  2621.         case ID_DETAIL_3:
  2622.                 map_set_prof(3);
  2623.                 break;
  2624.         case ID_DETAIL_4:
  2625.                 map_set_prof(4);
  2626.                 break;
  2627.         case ID_DETAIL_5:
  2628.                 map_set_prof(5);
  2629.                 break;
  2630.         case ID_LOCALISATION:
  2631.                 cmd_localisation();
  2632.                         break;
  2633.         case ID_POINT_ORIG_PUT:
  2634.                 cmd_point_orig();
  2635.                         break;
  2636.         case ID_POINT_ORIG_REM:
  2637.                 Pref.point_orig.existe=FALSE;
  2638.                         break;                  
  2639.         case ID_POINT_DEST_PUT:
  2640.                 cmd_point_dest();
  2641.                         break;
  2642.         case ID_POINT_DEST_REM:
  2643.                 Pref.point_dest.existe=FALSE;
  2644.                         break;  
  2645.         case ID_DONN_EXT:
  2646.                 cmd_donn_ext();
  2647.                         break;
  2648.         case ID_ORGANISATION:
  2649.                 cmd_organisation();
  2650.                 break;
  2651.         case ID_PREFS_AFF:
  2652.                 set(My_App->WI_Param,MUIA_Window_Open,(APTR)TRUE);
  2653.                 cmd_new_3d();
  2654.                 break;
  2655.         case ID_DONNEES:
  2656.                 Dtb_Read_Stats();
  2657.                 /*Dtb_Create_Liste_Data(My_App->LV_Datas);*/
  2658.                 set(My_App->WI_Datas,MUIA_Window_Open,(APTR)TRUE);
  2659.                 break;
  2660.         case ID_SCREEN:
  2661.                 cmd_change_screen();
  2662.                 break;
  2663.         case ID_GROUPE_CHG:
  2664. /*
  2665.                 get(My_App->PC_Pref_Pages,MUIA_Cycle_Active,&sel);
  2666.                 DoMethod(My_App->PC_Pref_Groupes,MUIM_Set,MUIA_Group_ActivePage,sel);
  2667. */
  2668.                 break;
  2669.         case ID_PR_X:
  2670.         case ID_PR_Y:
  2671.         case ID_PR_Z:
  2672.                 cmd_new_3d();
  2673.                 break;
  2674.         case ID_NO_FOND:
  2675.                 Del_Image();
  2676.                 break;
  2677.         case ID_SELECT:
  2678.                 bascule(My_App->LV_Deselect,My_App->LV_Select);
  2679.                 break;
  2680.         case ID_DESELECT:
  2681.                 bascule(My_App->LV_Select,My_App->LV_Deselect);
  2682.                 break;
  2683.         case ID_OK_DATAS:
  2684.                 cmd_redraw_datas();
  2685.                 break;          
  2686.         case ID_AFF_DRAP:
  2687.                 if (WI_Drapeaux==NULL && MUIMasterBase->lib_Version>=8)
  2688.                 {
  2689.                     /* Création d'une fenêtre MUI comprenant un groupe    */
  2690.                     /* virtuel contenant des groupes horizontaux contenant*/
  2691.                     /* chacun au plus 10 bitmaps representant les drapeaux*/
  2692.                     int     i,max_country;
  2693.                     CLIP    clip;
  2694.                     char    Buffer[100];
  2695.                     int     *P_Tab_Drapeau;
  2696.                     struct RastPort rp;
  2697.                     struct BitMap bm;
  2698.                     APTR GR_Drapeaux,GR_Drapeaux_Virtuel;
  2699.                     WI_Drapeaux = WindowObject,
  2700.                             MUIA_Window_Title, "Choose a flag",
  2701.                                 WindowContents, ScrollgroupObject,
  2702.                                     MUIA_Scrollgroup_Contents, GR_Drapeaux_Virtuel=VirtgroupObject,
  2703.                                     VirtualFrame,
  2704.                                     Child, GR_Drapeaux=GroupObject,
  2705.                                         MUIA_Group_Horiz, TRUE,
  2706.                                         End,
  2707.                                     End,
  2708.                                 End,
  2709.                             End;
  2710.                     DoMethod(My_App->App,OM_ADDMEMBER,WI_Drapeaux);
  2711.                     set ( WI_Drapeaux, MUIA_Window_Screen,(APTR)sC);
  2712.                     InitBitMap(&bm,4,wG->Width,wG->Height/5);
  2713.                     bm.Planes[0]=AllocRaster(wG->Width,wG->Height/5);
  2714.                     bm.Planes[1]=AllocRaster(wG->Width,wG->Height/5);
  2715.                     bm.Planes[2]=AllocRaster(wG->Width,wG->Height/5);
  2716.                     bm.Planes[3]=AllocRaster(wG->Width,wG->Height/5);
  2717.  
  2718.                     if (bm.Planes[3]!=NULL)
  2719.                     {
  2720.                         int nombre_drapeaux=0;
  2721.                         for (i=0;i<MAX_COUNTRY;i++)
  2722.                             Tab_Drapeaux[i]=NULL;
  2723.                         InitRastPort(&rp);
  2724.                         rp.BitMap=&bm;
  2725.                         rp.TmpRas=rpG->TmpRas;
  2726.                         rp.AreaInfo=&myareainfo;
  2727.                         max_country=get_max_country();
  2728.                         clip.minx=0;
  2729.                         clip.miny=0;
  2730.                         for(i=0;i<max_country;i++)
  2731.                         {
  2732.  
  2733.                             sprintf(Buffer,"flags/%s.flag",tab_country[i].name);
  2734.                             if(Flag_Read(Buffer,&P_Tab_Drapeau))
  2735.                             {
  2736.                               Object * bitmap;
  2737.                               if (nombre_drapeaux>10)
  2738.                               {
  2739.                                   GR_Drapeaux=GroupObject,
  2740.                                         MUIA_Group_Horiz, TRUE,
  2741.                                         End;
  2742.                                   DoMethod(GR_Drapeaux_Virtuel,OM_ADDMEMBER,GR_Drapeaux);
  2743.                                   nombre_drapeaux=0;
  2744.                               }
  2745.                               nombre_drapeaux++;
  2746.                               Tab_Drapeaux[i]=(struct BitMap *)malloc(sizeof(struct BitMap));
  2747.                               InitBitMap(Tab_Drapeaux[i],4,wG->Width/10,wG->Height/10);
  2748.                               Tab_Drapeaux[i]->Planes[0]=AllocRaster(wG->Width/10,wG->Height/10);
  2749.                               Tab_Drapeaux[i]->Planes[1]=AllocRaster(wG->Width/10,wG->Height/10);
  2750.                               Tab_Drapeaux[i]->Planes[2]=AllocRaster(wG->Width/10,wG->Height/10);
  2751.                               Tab_Drapeaux[i]->Planes[3]=AllocRaster(wG->Width/10,wG->Height/10);
  2752.                               if (Tab_Drapeaux[i]!=NULL)
  2753.                               {
  2754.                                   clip.maxx=clip.minx+wG->Width/10;
  2755.                                   clip.maxy=clip.miny+wG->Height/10;
  2756.                                   Flag_Draw(&rp,&clip,P_Tab_Drapeau,wG->WScreen->ViewPort.ColorMap);
  2757.                                   BltBitMap(&bm,0,0,Tab_Drapeaux[i],0,0,wG->Width/10,wG->Height/10,
  2758.                                             (long)0xc0,0xff,TAG_END);
  2759.                                   bitmap=BitmapObject,
  2760.                                     MUIA_Bitmap_Bitmap, Tab_Drapeaux[i],
  2761.                                     MUIA_Bitmap_Height,wG->Height/10,
  2762.                                     MUIA_Bitmap_Width,wG->Width/10,
  2763.                                     MUIA_FixHeight,wG->Height/10,
  2764.                                     MUIA_FixWidth,wG->Width/10,
  2765.                                     MUIA_InputMode, MUIV_InputMode_RelVerify,
  2766.                                     End;
  2767.  
  2768.                                   DoMethod(GR_Drapeaux,OM_ADDMEMBER,bitmap);
  2769.                                   DoMethod(bitmap,MUIM_Notify,MUIA_Pressed,FALSE,
  2770.                                     bitmap,3,MUIM_CallHook,&drapeau_select_hook,i);
  2771.                               }
  2772.                               free(P_Tab_Drapeau);
  2773.                             }
  2774.                          }
  2775.                          FreeRaster(bm.Planes[0],wG->Width,wG->Height/5);
  2776.                          FreeRaster(bm.Planes[1],wG->Width,wG->Height/5);
  2777.                          FreeRaster(bm.Planes[2],wG->Width,wG->Height/5);
  2778.                          FreeRaster(bm.Planes[3],wG->Width,wG->Height/5);
  2779.  
  2780.                          DoMethod(WI_Drapeaux, MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  2781.                             My_App->App,2,MUIM_Application_ReturnID,ID_CLOSE_DRAP);
  2782.                          set(WI_Drapeaux,MUIA_Window_Open,TRUE);
  2783.                      }
  2784.                 }
  2785.                 break;
  2786.         case ID_CLOSE_DRAP:
  2787.             {
  2788.                 int i;
  2789.                 set(WI_Drapeaux,MUIA_Window_Open,FALSE);
  2790.                 DoMethod(My_App->App,OM_REMMEMBER,WI_Drapeaux);
  2791.                 MUI_DisposeObject(WI_Drapeaux);
  2792.                 WI_Drapeaux=NULL;
  2793.                 for (i=0;i<MAX_COUNTRY;i++)
  2794.                     if (Tab_Drapeaux[i]!=NULL)
  2795.                     {
  2796.                         FreeRaster(Tab_Drapeaux[i]->Planes[0],wG->Width/10,wG->Height/10);
  2797.                         FreeRaster(Tab_Drapeaux[i]->Planes[1],wG->Width/10,wG->Height/10);
  2798.                         FreeRaster(Tab_Drapeaux[i]->Planes[2],wG->Width/10,wG->Height/10);
  2799.                         FreeRaster(Tab_Drapeaux[i]->Planes[3],wG->Width/10,wG->Height/10);
  2800.                         free(Tab_Drapeaux[i]);
  2801.                         Tab_Drapeaux[i]=NULL;
  2802.                     }
  2803.             }
  2804.                 break;
  2805.         case ID_PROJ:
  2806.                 get(My_App->CY_Proj,MUIA_Cycle_Active,&sel);
  2807.                 Pref.Flg_Proj_3D=FALSE;
  2808.                 switch(sel){
  2809.                         case 0:
  2810.                                 Pref.Type_Proj=PROJ_FLAT;
  2811.                                 break;
  2812.                         case 1:
  2813.                                 Pref.Type_Proj=PROJ_MERCATOR;
  2814.                                 break;
  2815.                         case 2:
  2816.                                 Pref.Type_Proj=PROJ_GLOBE;
  2817.                                 break;
  2818.                         case 3:
  2819.                                 Pref.Type_Proj=PROJ_FLAT;
  2820.                                 Pref.Flg_Proj_3D=TRUE;
  2821.                                 break;
  2822.                         default:
  2823.                                 Pref.Type_Proj=PROJ_FLAT;
  2824.                                 break;
  2825.                 }
  2826.                 redraw_map(-1,rpG);
  2827.                 /*printf("Type proj:%d\n",Pref.Type_Proj);*/
  2828.                 break;
  2829.         case ID_ADD_DATA:
  2830.                 cmd_add_data();
  2831.                 break;
  2832.  
  2833.         default:
  2834.                         break;
  2835.     }
  2836. }
  2837.  
  2838. /****************************************************************************/
  2839.  
  2840. void main_loop(void)
  2841. {
  2842.     UWORD   code            ;
  2843.     ULONG   class           ;
  2844.     APTR    object          ;
  2845.     int     x,y             ;
  2846.     int localisation_x,localisation_y;
  2847.     ULONG   signal_rec      ;
  2848.     int     Code_Action     ;
  2849.     ULONG   signal_mui=-1   ;
  2850.     USHORT  selection       ;
  2851.  
  2852.     struct  IntuiMessage *message;  /* the message the IDCMP sends us */
  2853.     struct  IntuiMessage copy_msg;
  2854.  
  2855.     {
  2856. /*      ULONG signal=0;*/
  2857.  
  2858.         while (quit_flag==FALSE)
  2859.         {
  2860.             if(signal_mui!=0)
  2861.             {
  2862.                 do
  2863.                 {
  2864.         Code_Action=DoMethod(My_App->App,MUIM_Application_Input,&signal_mui);
  2865.                     Do_Action(Code_Action);
  2866.                 }
  2867.                       while(signal_mui==0);
  2868.  
  2869.                 if(quit_flag==FALSE)
  2870.                 {
  2871.                     signal_rec=Wait( signal_mui | signal_wG | signal_win_info |
  2872.                                     signal_win_image|signal_win_localisation);
  2873.                 }
  2874.             
  2875.                 if(signal_rec & signal_win_image)
  2876.                 {
  2877.                     Del_Ext_Image();
  2878.                 }
  2879.                 if(signal_rec & signal_wG)
  2880.                 {
  2881.                     while( (message = (struct IntuiMessage *)
  2882.                         GetMsg(wG->UserPort) ) != NULL)
  2883.                     {
  2884.                         copy_msg=*message;
  2885.                         code = message->Code;  /* MENUNUM */
  2886.                         object = message->IAddress;  /* Gadget */
  2887.                         class = message->Class;
  2888.                         x= message->MouseX;
  2889.                         y= message->MouseY;
  2890.  
  2891.                         ReplyMsg((struct Message *)message);
  2892.                         if (flg_edit==FALSE)
  2893.                         {
  2894.                             switch(class)
  2895.                             {
  2896.                             case VANILLAKEY:
  2897.                                 if ((code>='0')&&(code<='5'))
  2898.                                 {
  2899.                                    map_set_prof(code-'0');
  2900.                                    redraw_map(-1,rpG);
  2901.                                 }
  2902.                                 break;
  2903.                             case RAWKEY:
  2904.                                 if (code==CURSORUP)
  2905.                                         map_move(rpG,0,-10);
  2906.                                     if (code==CURSORDOWN)
  2907.                                                 map_move(rpG,0,10);
  2908.                                     if (code==CURSORLEFT)
  2909.                                     map_move(rpG,-10,0);
  2910.                                     if (code==CURSORRIGHT)
  2911.                                     map_move(rpG,10,0);
  2912.                              
  2913.                                     break;
  2914.         
  2915.                             case MENUPICK:
  2916.                                 Prise_En_Compte=TRUE;
  2917.                                 for(selection=code;
  2918.                 (selection!=MENUNULL)&&(selection!=0);
  2919.                 selection=(ItemAddress(MyMenu,(LONG)selection))->NextSelect)
  2920.                                 {
  2921.     Code_Action=(int)GTMENUITEM_USERDATA(ItemAddress(MyMenu,(LONG)selection));
  2922.                                     if(Prise_En_Compte)
  2923.                                         Do_Action(Code_Action);
  2924.                                 }
  2925.                                 break;
  2926.                             case MOUSEBUTTONS:
  2927.                             case MOUSEMOVE :
  2928.                                   mouse_action(x,y,class,code);
  2929.                                   break;
  2930.                             }/* End of case */
  2931.                         }/* end de if */
  2932.                         else
  2933.                         {
  2934.                             edit_loop(©_msg);
  2935.                         }
  2936.                     }/*end de while*/
  2937.                             
  2938.                 }
  2939.             }
  2940.             if(signal_rec & signal_win_info)
  2941.             {
  2942.                while( (win_info!=NULL)&&
  2943.                       (message = (struct IntuiMessage *)
  2944.                             GetMsg(win_info->UserPort) ) != NULL)
  2945.                {
  2946.                     code = message->Code;
  2947.                     class = message->Class;
  2948.                     ReplyMsg((struct Message *)message);
  2949.  
  2950.                     switch(class)
  2951.                     {
  2952.                     case IDCMP_CLOSEWINDOW:
  2953.                         CloseWindowSafely(win_info);
  2954.                         win_info=NULL;
  2955.                         signal_win_info=0;
  2956.                         ActivateWindow(wG);
  2957.                         break;
  2958.                     case IDCMP_NEWSIZE:
  2959.                         cmd_info();
  2960.                         break;
  2961.                     case IDCMP_MOUSEBUTTONS:
  2962.                         /*printf("bouton appuyé dans l'info-win\n");*/
  2963.                         break;
  2964.                     }/* End of case */
  2965.                                 
  2966.                 }/* end de while*/
  2967.             }/* end de if*/
  2968.             if(signal_rec & signal_win_localisation)
  2969.             {
  2970.                static BOOL Flg_MOUSEBUTTONS=FALSE;
  2971.                while( (win_localisation!=NULL)&&
  2972.                       (message = (struct IntuiMessage *)
  2973.                             GetMsg(win_localisation->UserPort) ) != NULL)
  2974.                {
  2975.                     int X,Y;    /* declaration */
  2976.                     code = message->Code;
  2977.                     class = message->Class;
  2978.                     ReplyMsg((struct Message *)message);
  2979.  
  2980.                     switch(class)
  2981.                     {
  2982.                     case IDCMP_CLOSEWINDOW:
  2983.                         CloseWindowSafely(win_localisation);
  2984.                         win_localisation=NULL;
  2985.                         signal_win_localisation=0;
  2986.                         ActivateWindow(wG);
  2987.                         break;
  2988.                     case IDCMP_NEWSIZE:
  2989.                         cmd_localisation();
  2990.                         break;
  2991.                    case IDCMP_MOUSEBUTTONS:
  2992.                         if (Flg_MOUSEBUTTONS==FALSE)
  2993.                         {
  2994.                             localisation_x=message->MouseX
  2995.                                 -win_localisation->BorderLeft;
  2996.                             localisation_y=message->MouseY
  2997.                                 -win_localisation->BorderTop;
  2998.                             X=localisation_x*(clip_max.maxx-clip_max.minx)
  2999.         /(win_localisation->Width-win_localisation->BorderRight)+clip_max.minx;
  3000.                             Y=(localisation_y)*(clip_max.maxy-clip_max.miny)
  3001.                                 /(win_localisation->Height)+clip_max.miny;
  3002.                             map_center(rpG,X,Y);   
  3003.                             Flg_MOUSEBUTTONS=TRUE;
  3004.                         }
  3005.                         else
  3006.                             Flg_MOUSEBUTTONS=FALSE;
  3007.                         break;
  3008.                     }/* End of case */
  3009.                                 
  3010.                 }/* end de while */
  3011.             }/* end de if */            
  3012.  
  3013.         }/* Fin de WHILE quit_flag */
  3014.     }
  3015.     return;
  3016. }
  3017.  
  3018.  
  3019. void aff_surface(void)
  3020. {
  3021.     char buffer[60];
  3022.     int sx=Pref.clip_cur.maxx-Pref.clip_cur.minx;
  3023.     float angle_maxy=Map_Convert_Angle(Pref.clip_cur.maxy);
  3024.     float angle_miny=Map_Convert_Angle(Pref.clip_cur.miny);
  3025.     double h=RAYON*(sin(angle_maxy)-sin(angle_miny));
  3026.     double surface=2*PI*RAYON*h*sx/36000;
  3027.     sprintf(buffer,"View area: %.0f km²",
  3028.                     surface);
  3029.     IPrint(rpG,8,3*Text_Font->tf_YSize+2,buffer,-1);
  3030. }
  3031.  
  3032. void aff_distance(void)
  3033. {
  3034.     if ((Pref.point_orig.existe==TRUE)&&(Pref.point_dest.existe==TRUE))
  3035.     {
  3036.         char buffer[40];
  3037.         sprintf(buffer,"distance: %.3f km",distance_orig_dest);
  3038.         IPrint(rpG,8,2*Text_Font->tf_YSize+2,buffer,-1);
  3039.     }
  3040. }
  3041.  
  3042.  
  3043. /****************************************************** reselect() ******/
  3044.  
  3045. void reselect(struct RastPort * r)
  3046. {
  3047.     int i;
  3048.     if (Pref.country_sel!=-1)
  3049.     {
  3050.         fill_country(Pref.country_sel,1,r);
  3051.     }
  3052.     if (Pref.Flag_Echelle)
  3053.         Map_Aff_Echelle(r);
  3054.     if (Pref.Flag_Surface)
  3055.         aff_surface();
  3056.     if (Pref.Flg_Aff_Elem_Rem)
  3057.         for (i=0;i<get_max_country();i++)
  3058.             aff_elem_rem(r,i);
  3059.     if (Pref.Flg_Aff_Trajectoires)
  3060.         Map_Aff_Trajectoires(r,NULL);
  3061.     map_aff_point(r,&Pref.point_orig,0);
  3062.     map_aff_point(r,&Pref.point_dest,1);
  3063.     Draw_Chemin(r);
  3064.     if (Pref.Flag_Distance)
  3065.         aff_distance();
  3066.     ActivateWindow(wG);
  3067. }
  3068.  
  3069. void aff_elem_rem(struct RastPort * r,int numero)
  3070. {
  3071.     if (tab_country[numero].P_Elem_Rem!=NULL)
  3072.     {
  3073.         ELEM_REM * element=tab_country[numero].P_Elem_Rem;
  3074.         while (element!=NULL)
  3075.         {
  3076.             Map_Aff_Elem_Rem(r,element);
  3077.             element=element->P_Next;
  3078.         }
  3079.     }
  3080. }       
  3081.